参考链接
https://blog.csdn.net/weixin_34498545/article/details/112631706
进行初始化
plt.figure(figsize = (8,6))
ax = plt.gca()
调整坐标轴范围
x轴
ax.set_xlim()
y轴
ax.set_ylim()
设置在 0 - 8 之间
ax.set_xlim(0,8)
ax.set_ylim(0,8)
设置 x 轴 y 轴 标题
("内容",fontsize = ,color = ,alpha = , bbox = ,)
ax.set_xlabel()
ax.set_ylabel()
参数示例
ax.set_xlabel("X轴",fontsize = 14,color = 'b',alpha = 0.7,bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='blue',lw=1 ,alpha=0.7))
ax.set_ylabel("Y轴",fontsize = 14,color = 'b',alpha = 0.7,bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='blue',lw=1 ,alpha=0.7))
修改默认刻度文字
(列表 , family = , fontsize = ,)
ax.set_xticklabels()
ax.set_yticklabels()
ax.set_xticklabels(['A','B','C','D','E','F','G'])
ax.set_yticklabels(['鉴','图','化','视','可','注','关'],
family = 'SimHei',fontsize = 14)
突出主副刻度
使用 tick_params 对刻度线进行调整
tick_params(which = , length = , labelsize = ,)
tick_params(which='major',length=8,labelsize=10)
tick_params(which='minor',length=4)
调整 坐标轴 刻度 距离
默认刻度 locator
位置 MultipleLocator
样式 FormatStrFormatter
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
xmajorLocator = MultipleLocator(1)
ax.xaxis.set_major_locator(xmajorLocator)
ymajorLocator = MultipleLocator(1)
ax.yaxis.set_major_locator(ymajorLocator)
xminorLocator = MultipleLocator(0.25)
ax.xaxis.set_minor_locator(xminorLocator)
yminorLocator = MultipleLocator(0.25)
ax.yaxis.set_minor_locator(yminorLocator)
MultipleLocator(1) 表示刻度之间的间隔为 1