y1,label='Line 1')ax.plot(x,y2,label='Line 2')# 将图例放置在绘图区域外部ax.legend(bbox_to_anchor=(1.05,1),loc='upper left')# 调整布局plt.tight_layout()# 添加标题plt.title('Legend Outside Plot - how2matplotlib
在这种情况下,我们可以使用subplot函数创建多个子图,并为每个子图单独设置图例的位置。下面是一个示例代码: importmatplotlib.pyplotasplt# 创建第一个子图plt.subplot(2,1,1)plt.plot([1,2,3,4],[1,4,9,16])plt.legend(['Line 1'],loc='upper right',bbox_to_anchor=(1.2,1))# 创建第二个子图plt...
In thisPython tutorial, we will discussPut legend outside plot matplotlibin python. Here we will cover different examples related to legend outside plot usingmatplotlib. And we will also cover the following topics: Put legend outside plot matplotlib Matplotlib set legend outside plot Matplotlib set...
plt.subplot(221) plt.plot(X,C) plt.subplot(2,2,2)#可以隔开,也可以不隔开plt.plot(X,S) plt.subplot(212) plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) plt.show() 0x06 参考 1.CSDN开码牛-matplotlib命令与格式:图例legend语法及设置 2.CSDNweixin_41950276-plt.legend( )函数,给图像加上...
plt.legend(loc='best',facecolor='blue') #设置图例背景颜色,若无边框,参数无效 1. 2. 3. 对于边框还可以采用面向对象方式: legend = plt.legend(["First", "Second"]) frame = legend.get_frame() frame.set_facecolor('blue') 1. 2.
Legend:外部 y1 = df['HP'][:10] y2 = df['Attack'][:10] x = df['Name'][:10] fig = plt.figure() ax = plt.subplot(111) ax.plot(x, y1, label='y1 = Pokemon HP') ax.plot(x, y2, label='y2 = Pokemon Attack') plt.title('Legend outside') chartBox = ax.get_position...
Legend图例 给图做图例,只需要在plt.plot()加上label参数即可,然后执行plt.legend()即可 x=np.linspace(-2,2,50) y1=2*x+1 y2=x**2 plt.plot(x,y2,label='up') plt.plot(x,y1,color='red',linewidth=1.0,linestyle='--',label='down') ...
fontsize=13) plt.legend(loc=0,fontsize=13)#图例字号 plt.grid() #第4张子图 plt.subplot(2,2...
# 设置、显示legend plt.legend(loc='best') # loc参数设置图例显示的位置 # 设置图表的标题 plt.title('cos&sin') plt.text(-np.pi, 1, '任意位置添加文字',fontdict={'size': 10, 'color': 'y'}) # text在图中任意位置添加文字,前两个参数是左下角的位置坐标 ...
ax = fig.add_subplot(111, projection='3d') x = np.random.normal(0, 1, 100) y = np.random.normal(0, 1, 100) z = np.abs(np.random.randn(100)) ax.scatter(x, y, z, c=z, cmap='plasma') ax.set_xlabel('X坐标')