ax1.plot(x, x ** 3, label='cubic') ax1.set_xlabel('x label') # 设置x轴 ax1.set_ylabel('y label') # 设置y轴 ax1.legend() # 增加图例 # 显示图片 plt.show() 运行结果 3.实例3 程序 import matplotlib.pyplot as plt import numpy as np if __name__ == '__main__': # pypl...
p1.set_xlabel("t",fontsize=14)#p1.set_title("A simple example",fontsize=18)p1.grid(True) p1.legend() tx= 0.5ty= 0.9p1.text(tx,ty,label_f0,fontsize=15,verticalalignment="top",horizontalalignment="left") p2.axis([4,4.5,-0.02,0.03]) p2.set_ylabel("v",fontsize=14) p2.se...
ax.set_xlabel("苹果销售量",fontsize=18) ax.set_yticks(np.linspace(1,13,7)) ax.set_xticks(np.linspace(50,100,5)) for a,b in zip(app,np.linspace(1,13,7),): ax.text(a+2,b-0.3,"%skg"%b,fontsize=12) ax.spines["top"].set_visible(False)#上轴不显示ax.spines["right"].s...
例如,如果已有x轴的刻度位置为1, 2, 3,想要将其标签设置为'A', 'B', 'C',可以使用以下代码:import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5, 6] plt.bar(x, y) plt.xticks(x) plt.set_xticklabels(['A', 'B', 'C']) plt.show() 使用plt.xlabel()函数来设置x轴的...
ax1.set_xlabel('A') # 设置x标签为A ax1.set_ylabel('B') #设置y标签为B 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. (3)标题的设置: 面对对象: axes.set_title(title_name,color,fontsize) ...
plt.xlabel() X轴文本标签 plt.ylabel() Y轴文本标签 plt.title() 图表标题 plt.text() 任意位置增加文本 plt.annotate() 任意位置增加带箭头的注释文本 plt.annotate(string,xy=arrow_crd,xytext=text_crd,arrowprops=dict) string:要显示的字符串 ...
axs[0].set_xlabel('x') axs[0].set_ylabel('sin(x)') axs[0].legend() axs[0].set_title('Sine Function') # 第二个图 axs[1].plot(x, y2, 'r-', label='cos(x)') axs[1].set_xlabel('x') axs[1].set_ylabel('cos(x)') ...
ax.set_xlabel('Smarts') ax.set_ylabel('Probability density') ax.set_title(r'Histogram of IQ: $\mu=100$, $\sigma=15$') # Tweak spacing to prevent clipping of ylabel fig.tight_layout() plt.show() 4、路径示例 可以使用matplotlib.path模块在matplotlib中添加任意路径 : ...
#ax.set_xlabel("星期")#添加x轴坐标标签,后面看来没必要会删除它,这里只是为了演示一下。 ax.set_ylabel("销售量",fontsize=16)#添加y轴标签,设置字体大小为16,这里也可以设字体样式与颜色 ax.set_title("某某水果店一周水果销售量统计图",fontsize=18,backgroundcolor='#3c7f90',\ ...
p1.set_xlabel('year') p1.set_ylabel('num') #右侧折线图 p2 = p1.twinx() p2.plot(year,s,color='red',label='right map') p2.legend(loc='upper right') p2.set_ylabel('rate') p2.set_ylim(-1,2) #标题 plt.title("double map") ...