Python中使用legend()函数的方法-import numpy as np import matplotlib.pyplot as plt # X-axis values x = [1, 2, 3, 4, 5] # Y-axis values y = [1, 4, 9, 16, 25] # Function to plot plt.plot(x, y) # Function add a legend
plt.legend([p3, p4], ['label', 'label1'], loc='lower right', scatterpoints=1) # Add l1 as a separate artist to the axes plt.gca().add_artist(l1) import matplotlib.pyplot as plt line1, = plt.plot([1,2,3], label="Line 1", linestyle='--') line2, = plt.plot([3,2,1...
plot(x, y, x, ym1, x, ym2, 'o') #设置线的属性 plt.setp(lines[0], linewidth=1) plt.setp(lines[1], linewidth=2) plt.setp(lines[2], linestyle='-',marker='^',markersize=4) #线的标签 plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'), loc='upper ...
scatterpoints the number of points in the legend for scatter plot 为散点图图例条⽬创建的标记点数 scatteryoffsets a list of yoffsets for scatter symbols in legend 为散点图图例条⽬创建的标记的垂直偏移量 frameon If True, draw the legend on a patch (frame).控制是否应在图例周围绘制框架 fa...
plt.plot(x,x*x) plt.show 具体实现效果: 5. 添加图例-legend 当线条过多时,我们设置不同颜色来区分不同线条。因此,需要对不同颜色线条做下标注,我们实用 legend 接口来实现。 importnumpyasnp importmatplotlib.pyplotasplt # 显示中文 plt.rcParams['font.sans-serif'] = [u'SimHei'] ...
# 或者在 plot 中不使用 label 参数,直接使用如下语句 # 顺序遵从 plot 的画线顺序 # plt.legend(['line1', 'line2']) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 9.设置显示中文(局部) 一般用来设置中文的属性都是fontproperties,除了图例用的是prop,这个在上面说到过!
plt.plot(x,np.cos(x)) #在ax1里画第2个图。 ax2 =fig.add_subplot(2,2,2) # 如果第2次为(3,2,1),画布可能有重叠的地方。 plt.plot(x,np.sin(x*0.5))# 在ax2里画图 plt.scatter(x,np.sin(x),label='SCATTER') # 散点图
ax4.plot([1,2,3,4],[1,2,3,3]) plt.show() 简单子图创建 ax1=fig.add_subplot(221),221里面前两个代表的是画布划分的行数和列数,公共分为4个子图,最后一个1是代表,现在选中第一个子图。 import matplotlib.gridspec as gridspec#调用网格 ...
lines = plt.plot(x, y, x, ym1, x, ym2, 'o') #设置线的属性 plt.setp(lines[0], linewidth=1) plt.setp(lines[1], linewidth=2) plt.setp(lines[2], linestyle='-',marker='^',markersize=4) #线的标签 plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'...
x=np.linspace(0,10,100)y1=np.sin(x)y2=np.cos(x)plt.fill(x,y1,'r',alpha=0.3,label='sin(x)')plt.fill(x,y2,'b',alpha=0.3,label='cos(x)')plt.title('Area Plot Example - how2matplotlib.com')plt.xlabel('X-axis')plt.ylabel('Y-axis')plt.legend()plt.show() ...