label='Line 1')ax.plot([1,2,3,4],[2,3,4,1],label='Line 2')ax.legend(title='Data from how2matplotlib.com')ax.set_title('Plot with Legend Title using ax.legend()')ax.set_xlabel('X-axis')ax.set_ylabel('Y-axis')plt.show()...
3,5,7,9]# 创建图表plt.figure(figsize=(8,6))plt.plot(x,y1,label='Series 1')plt.plot(x,y2,label='Series 2')# 添加图例并自定义标题样式legend=plt.legend(title='Data from how2matplotlib.com')legend.get_title().set_fontsize('14')legend.get_title().set_fontweight('bold')legend.ge...
ax.set_xlabel(f"xlabel {i}") ax.scatter( np.random.random(30) * 0.45 + 0.3, np.random.random(30) * 0.45 + 0.3, label="label for data", alpha=0.3, ) ax.legend(title=f"Legend {i} title", fontsize=8) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_title(f"Title {i} ...
legend(title=f"Legend {i} title", fontsize=8) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_title(f"Title {i} left", loc="left", fontsize=8) ax.set_title(f"Title {i} right", loc="right", fontsize=10) ax.set_title(f"Title {i} center", loc="center", fontsize=14)...
color on the legend. legend.get_frame().set_facecolor('#00FFCC') legend.get_title().set_...
5,2]}) plt.plot(df) legend = plt.legend(['Day 1','Day 2']) legend.set_title("Legend"...
x = np.linspace(0, 2, 100)fig, ax = plt.subplots() # Create a figure and an axes.l1 = ax.plot(x, x, label="linear")l2 = ax.plot(x, x ** 2, label="quadratic")l3 = ax.plot(x, x ** 3, label="cubic")ax.set_title("Simple Plot")ax.legend()plt.show()我们可以调整...
使用到的set_title()参数有很多,介绍几个常用的 fontsize:默认12,可选参数还有'xx-small', 'x-small', 'small', 'medium', 'large','x-large', 'xx-large' backgroundcolor:背景颜色 fontweight:字体粗细,可选参数为'light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black' color:...
实际上,title标题方法的大部分参数也适用于xlabel和ylabel坐标轴标签方法。 三、图例的配置 legend图例方法有很多可以配置的参数和选项: 对于loc这个图例在坐标轴中的放置位置,有两种表示方法:数字或者字符串,其对应关系如下: 0: ‘best' : 自动选择最适合的位置 ...
plt.title("Simple Plot") plt.legend() plt.show() 它在子图上的用法基本上一模一样,我们来看个例子: 我们可以看到对于ax1这张子图来说,我们做的事情和plt是一样的,就是在调用plot的时候标上了label,然后在show之前调用了legend方法。 最后来介绍一下legend的参数,其实legend有很多参数,我们选择其中比较常用的...