【发布时间】:2020-10-04 21:19:09
【问题描述】:
为了在上下轴上添加箭头,我首先将刺的颜色设置为“无”。
然后我使用axes.arrow() 函数绘制箭头。
最后,我使用axes.set_ticks() 函数重置刻度。
我想保留顶轴的小刻度。但正如您所看到的,左上角的小刻度超出了箭头的范围。如何删除超出范围的部分?
【问题讨论】:
标签: python matplotlib xticks
为了在上下轴上添加箭头,我首先将刺的颜色设置为“无”。
然后我使用axes.arrow() 函数绘制箭头。
最后,我使用axes.set_ticks() 函数重置刻度。
我想保留顶轴的小刻度。但正如您所看到的,左上角的小刻度超出了箭头的范围。如何删除超出范围的部分?
【问题讨论】:
标签: python matplotlib xticks
可以通过set_minor_locator 使用FixedLocator 设置次要刻度。
一个例子:
from matplotlib import pyplot as plt
from matplotlib.ticker import FixedLocator
fig, ax = plt.subplots()
ax.set_xscale('log')
ax.set_xlim(10**6, 1)
ax.set_xticks([10**n for n in range(-1, 5)])
ax.xaxis.set_minor_locator(FixedLocator(
[k * 10**n for n in range(-1, 5) for k in range(2, 10) if k * 10**n <= 30000]))
ax.xaxis.tick_top()
plt.show()
【讨论】: