我需要通过显示'x‘内部的'o’来编辑图例,我用它来标记曲线的某些部分,但我无法解决这个问题,因为我使用了一种复杂的方法来突出显示高和低部分。
fig = plt.figure(figsize=(20, 15))
ax = fig.add_subplot( 2, 1, 1 )
bx = fig.add_subplot( 2, 1, 2 )
ax.plot( time1List, tempList, marker='x', linestyle='', zorder=100 )
ax.plot( time2List, fit_func( time2List, *sol ), zorder=0 )
ax.set_title('Fitting whole MPs on standrad thermal profile ', fontweight='bold', fontsize=25)
ax.set_xlabel('cycles', fontsize=20)
ax.set_ylabel('Thermal regime', fontsize=20)
ax.set_yticks( [-40,-20,0,25,50,75,100,125,150] )
#patch = Patch(facecolor='orange', edgecolor='r', label='Color patch')
#lgd = ax.legend(handles=[time1List, time2List, patch], loc='lower right')
#add_patch(lgd)
#ax.legend(loc='best')
red_patch = mpatches.Patch(color='red', label='High regime')
blue_patch = mpatches.Patch(color='blue', label='Low regime')
plt.legend(handles=[red_patch, blue_patch], loc='best', fontsize=20)
bx.plot( time1List, tempList, marker='x', linestyle='' )
bx.plot( time2List, fit_func( time2List, *sol ) )
bx.plot( rampX, rampY, linestyle='', marker='o', markersize=10, fillstyle='none', color='r')
bx.plot( topX, topY, linestyle='', marker='o', markersize=10, fillstyle='none', color='#00FFAA')
bx.plot( botX, botY, linestyle='', marker='o', markersize=10, fillstyle='none', color='#80DD00')
bx.set_title('Fitting part of MPs on standrad thermal profile ', fontweight='bold', fontsize=25)
bx.set_xlabel('cycles', fontsize=20)
bx.set_ylabel('Temperature [℃]', fontsize=20)
bx.set_xlim( [ 0, 800 ] )
plt.show()

对于如何解决这个问题,有什么建议吗?
发布于 2019-09-02 05:30:13
你为了得到那个十字准线标记画了两次图。使用创建标记的方法,您将无法使用任何标准方法创建带有十字准线的图例。
您可以使用$\\bigotimes$直接获取标记。那么使用legend就会很简单。只需为绘图中的每个对象定义label,即可在图例中显示:
fig, ax = plt.subplots()
X = np.arange(10)
Y1 = np.arange(10)
Y2 = np.arange(10)/2 + 3
attrs = {'marker': '$\\bigotimes$', 'linestyle': '', 'markersize': 10, 'markeredgewidth': 0.5}
ax.plot(X, Y1, c = 'g', label='Y1', **attrs)
ax.plot(X, Y2, c = 'r', label='Y2', **attrs)
ax.legend()

https://stackoverflow.com/questions/57749560
复制相似问题