import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
#显示绘图中的中文
font = {'family':'SimHei',
'weight':'bold',
'size':'12'}
plt.rc('font', **font)
plt.rc('axes', unicode_minus=False)
# 获取当前坐标轴
#ax = plt.gca()
# 设置水平坐标轴的主刻度定位器
#ax.xaxis.set_major_locator(plt.NullLocator(1))#主刻度不显示
#设置水平坐标轴的次刻度定位器为多点定位器,间隔0.1
#ax.xaxis.set_minor_locator(plt.MultipleLocator(0.1))#间隔0.1
#案例
Locators = ['plt.NullLocator()',
'plt.MaxNLocator(nbins = 4)',
'plt.FixedLocator([3,6,9])',
'plt.AutoLocator()']
plt.figure('Locators',facecolor='lightgray')
for i ,locator in enumerate(Locators):
plt.subplot(len(Locators),1,i+1)
#x轴的可视范围
plt.xlim(1,10)
#获取当前坐标轴
ax = plt.gca()
# 设置水平坐标轴的主刻度定位器
ax.xaxis.set_major_locator(plt.Mu
matplotlib 绘图坐标定位器 笔记
最新推荐文章于 2023-12-03 20:17:59 发布