python - Matplotlib:还显示小刻度的标签

标签 python matplotlib plot axis-labels

matplotlib 中,当我在一个轴上使用 log 刻度时,该轴可能会没有主要刻度,< strong>只有轻微的。所以这意味着整个轴没有标签显示。

我如何指定小刻度也需要标签?

我试过:

plt.setp(ax.get_xticklabels(minor=True), visible=True)

...但它并没有成功。

最佳答案

可以在相应的轴上使用set_minor_tickformatter:

from matplotlib import pyplot as plt
from matplotlib.ticker import FormatStrFormatter

axes = plt.subplot(111)
axes.loglog([3,4,7], [2,3,4])
axes.xaxis.set_minor_formatter(FormatStrFormatter("%.2f"))
plt.xlim(1.8, 9.2)
plt.show()

enter image description here

关于python - Matplotlib:还显示小刻度的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165435/

相关文章:

python - 检查可打印的 Unicode

python - matplotlib savefig() 空白 - show() 不是

r - 按组变量对绘图箱图中的抖动进行着色

重组 sf multi-plot 并添加图例

Python按具有相同属性的列表中的相邻项目分组

python - 在 Ubuntu 11.04 上加载 pygtk 时出现问题

python-3.x - matplotlib 动态子图数量

matlab - 填充用 patch 函数绘制的矩形

python - 带有networkx的超图

python - 在 numpy/matplotlib 中以图形和数字方式求解线性二次方程组?