python - 控制标签缩写 matplotlib

标签 python matplotlib

我正在绘制非常简单的条形图,其中 x 值是很大的数字。 Matplotlib 似乎通过使用绘图上的值中的最后 2-3 个数字,然后在“图例”中放置前 x 个数字来处理此问题。因此,在示例中,我显示的第一个刻度代表数字 8245540,在绘图上使用 40,并在图例中使用 82455。

有没有办法控制数字的缩写方式或在标记 x 轴时简单地使用完整数字?

下面是一个示例。

enter image description here

最佳答案

使用以下内容:

from matplotlib.ticker import FormatStrFormatter
# plot here
pyplot.gca().xaxis.set_major_formatter(FormatStrFormatter('%d'))

有关更多详细信息,请参阅此:Matplotlib: Specify format of floats for tick lables

关于python - 控制标签缩写 matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44706897/

相关文章:

python - Python 中的复杂数据提取

python - 情绪分析 - 交叉验证无效分数

Python 模块在 IDE 之间是不同的

python - Matplotlib 堆叠直方图 numpy.ndarray 错误

python - 如何自定义 mplfinance.plot?

python - Python 中的双重求和

Python 基础 - 为什么我的文件内容不打印?

python - Tkinter - 将多列添加到 Treeview

python - 使用 matplotlib 刷新我的饼图?

python - matplotlib 默认移除轴标签偏移量