首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用matplotlib在python的图例中显示x标记中的'o‘?

如何使用matplotlib在python的图例中显示x标记中的'o‘?
EN

Stack Overflow用户
提问于 2019-09-02 05:15:19
回答 1查看 67关注 0票数 0

我需要通过显示'x‘内部的'o’来编辑图例,我用它来标记曲线的某些部分,但我无法解决这个问题,因为我使用了一种复杂的方法来突出显示高和低部分。

代码语言:javascript
复制
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() 

对于如何解决这个问题,有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-02 05:30:13

你为了得到那个十字准线标记画了两次图。使用创建标记的方法,您将无法使用任何标准方法创建带有十字准线的图例。

您可以使用$\\bigotimes$直接获取标记。那么使用legend就会很简单。只需为绘图中的每个对象定义label,即可在图例中显示:

代码语言:javascript
复制
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()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57749560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档