Python program for adding legend to a plot # Data Visualization using Python# Adding a Legendimportnumpyasnpimportmatplotlib.pyplotasplt x=np.linspace(0,2,100)# Example 1plt.figure()plt.plot(x,x+2,label='linear'
The above plot is the same as the one created in the previous example. The only difference is that, here, we have added a legend to the plot. In theplt.plot()function, we defined a new argumentlabel =where we parsed the legend label for each of the two lines plotted on the graph....
In the code above, we added alabel='Line Plot'argument to theplotfunction, which specifies the label for the line plot. We then called thelegendfunction to display the legend on the plot. This legend will include the line plot with the specified label. Adding Legends to Part of a Plot ...
接下来,我们可以使用plot函数来绘制图形。这里我们以绘制一条简单的曲线为例。代码如下所示: x=[1,2,3,4,5]y=[1,4,9,16,25]plt.plot(x,y,label='y=x^2') 1. 2. 3. 步骤四:创建并调整图例大小 在绘制图形之后,我们需要创建图例,并对图例的大小进行调整。可以使用plt.legend()函数来创建图例,并...
There are a few important elements that can be easily added to plots. 有几个重要元素可以轻松添加到绘图中。 For example, we can add a legend with the legend function. 例如,我们可以使用图例功能添加图例。 We can adjust axes with axis, where axis is spelled A-X-I-S. 我们可以用axis调整轴...
1,11,1)2plt.figure()3plt.title(u'训练性能', fontproperties=font)4plt.plot(x, x * 2, label=u'训练误差')5plt.plot(x, x * 3, label=u'验证误差')6plt.ylabel(u'误差', fontproperties=font)7plt.xlabel(u'训练次数', fontproperties=font)8plt.legend(prop =font)9fig_name = save_path...
plot1.axes_labels(['x coordinate ','y coordinate']) plot1.axes_labels_size(1.2) plot1.legend(True) plot1.show(frame=True,legend_loc='lower right',legend_markerscale=0.6,legend_font_size=10) 本来自己的原意是在legend中只出现1个圆点,1个点代表在这个二维空间中出现的10个点的意思是”Original...
(True, alpha=0.3) ax4.legend() plt.tight_layout() plt.show() return fig def _plot_candlestick(self, ax, df): """绘制K线图""" for i in range(len(df)): row = df.iloc[i] # K线颜色 color = 'red' if row['收盘'] >= row['开盘'] else 'green' # 影线 ax.plot([i, i],...
ax4.legend() # 策略说明 fig.text(0.1,0.01, '【粉+黄做多】【粉+蓝做空】【粉色做多】【蓝色做空】【黄色做多】【红色倍量】【绿色缩量】', color='cyan', fontsize=12) plt.tight_layout() plt.show() # 执行可视化 visualize_data(df[-100:])# 展示最近100天的数据 ...
0))l1,=plt.plot(x,y2,label='up')#label: 名字l2,=plt.plot(x,y1,color='red',linewidth=1.0,linestyle='--',label='down')#loc: best、upper right ……, handles:线,label:自定义名字plt.legend(handles=[l1,l2],labels=['aaa','bbb'],loc='best')#也可以只选择显示部分线的legendplt....