Python plt.legend绘图图例显示不全只显示一个字符
上原码:ax.legend(labels = 'band',loc='upper center')ax.legend(labels = 'band',loc='best')结果图:原因是因为将图例放到legend里了,应该放到plt.plot里,改后代码:plt.plot(timeData,intensityData,c = 'blue',linewidth = 1,label='band')ax
·
上原码:
ax.legend(labels = 'band',loc='upper center')
ax.legend(labels = 'band',loc='best')
结果图:
原因是因为将图例放到legend里了,应该放到plt.plot里,改后代码:
plt.plot(timeData,intensityData,c = 'blue',linewidth = 1,label='band')
ax.legend(loc='best')
plt.plot(timeData,sum_y,linewidth = 1,label='band')
ax.legend(loc='best')
结果图:
然后再设置一下图例大小和去除边框,
legend_font = {
'family': 'Times New Roman', # 字体
'style': 'normal',
'size': 28, # 字号
'weight': "normal", # 是否加粗,不加粗
}
#ax.legend(labels = 'band',loc='best')
ax.legend(loc='upper right',frameon=False,prop=legend_font)
如果给多条线附label时,则需要在legend中给出labels,上码子:
columns = ['time(ns)','400','435','470','505','540','575','610','645','680','715','750','785','820','855','890','925',
'960','995','1030','1065','1100','1135','1170','1205','1240','1275','1310','1345','1380','1415',
'1450','1485']
plt.plot(timeData,sum_y,linewidth = 1)
legend_font = {
'family': 'Times New Roman', # 字体
'style': 'normal',
'size': 10, # 字号
'weight': "normal", # 是否加粗,不加粗
}
ax.legend(labels=columns[1:32],loc='upper right',frameon = False,prop=legend_font,ncol = 2)
更多推荐
已为社区贡献3条内容
所有评论(0)