python - 如何选择对数图中 n 个位置的刻度?

标签 python matplotlib

在 matplotlib 中,有时在 loglog 图中主要刻度线彼此靠得太近。除了手动设置它们,是否可以使用类似于 MaxNLocator 的东西在对数刻度中的 n 个位置放置刻度?

import numpy as np
import pylab as p

x=np.logspace(1,20,10)

fig=p.figure()
ax1=fig.add_subplot(121)
ax1.loglog(x,x,'o')
ax2=fig.add_subplot(122)
ax2.loglog(x,x,'o')
fig.show()

Figure

最佳答案

在最新版本的 matplotlib (1.2.0) 中,获得更类似于 MaxNLocator 的内容 你也可以使用@unutbu 的解决方案

ax.xaxis.set_major_locator(ticker.LogLocator(numticks=6))

关于python - 如何选择对数图中 n 个位置的刻度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9275406/

相关文章:

python - ubuntu上scrapy的安装问题

python - 更改 matplotlib 中日期时间轴的格式

python - Pandas 条形图到 numpy 数组

python - 带有两个 y 尺度的 Seaborn despine (twinx)

python - 如何在python中的多个线程之间正确共享信息?

python - 运行PySpark命令时出错

python - 如何设置循环 pygame.mixer 播放列表在后台播放?

python - SQLAlchemy 条件关系

python - 获取 matplotlib 中一行的图例标签

python - 在 matplotlib 中绘制 csv 文件