是否有一个股票代码格式化程序可以避免在对数刻度上重叠?

问题描述 投票:0回答:1

是否可以使用ticker自动避免刻度线重叠?当我运行以下代码时,您可以看到刻度太多,并且由于重叠而难以辨认。

import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter, EngFormatter
import numpy as np

fig = plt.figure(num='design', clear=True)
ax = fig.subplots()

v = np.logspace(np.log10(80), np.log10(7e3), 2)
ax.semilogx(v, np.ones_like(v), color=(0,0,0,0))
ax.grid(which='both', axis='x')
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_major_formatter(EngFormatter(unit='V'))
ax.xaxis.set_minor_formatter(EngFormatter(unit='V'))
ax.set_xlabel('voltage')

结果:

python matplotlib
1个回答
0
投票

如果您不需要每个刻度,请注释设置次要刻度单位的行(

set_minor_formatter
),因为这就是导致它们显示的原因。没有数据,它看起来很糟糕,但如果你确实有跨越很大范围的数据(这需要对数刻度),那么它看起来会更正常。

如果您需要更多蜱虫,那么您可以使用蜱虫定位器以所需的频率设置蜱虫(Stack Overflow 上有很多关于此的问题)。

© www.soinside.com 2019 - 2024. All rights reserved.