python Matplotlib给坐标轴标签添加文本框

import matplotlib.pyplot as plt
import numpy as np
x=["q","w","e","r","t","y"]#不变的依然是x表示标签值
y=[4,6,7,6,3,9]
plt.barh(x,y,align="center",color="green",alpha=0.6,label="barh")
box=dict(fc="red",pad=2,alpha=0.4)
#给坐标轴的标签加上文本框,就是使用bbox函数
plt.xlabel("xaxis",bbox=box)
plt.ylabel("ylabel",bbox=dict(fc="green",ec="black",pad=2,alpha=0.5))
plt.grid(True,color="red",ls="-.",axis="y")#axis表示值显示哪个轴的虚线
plt.legend()
plt.show()

猜你喜欢

转载自www.cnblogs.com/shunguo/p/11398166.html