You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Matplotlib绘图中Y轴大数值完整显示而非科学计数法形式?

How to Force Matplotlib Y-Axis to Show Full Original Values Instead of Scientific Notation?

Got it, this is a common quirk with Matplotlib—it automatically switches to scientific notation when it thinks numbers are too large to display neatly, even if the actual value range is tiny. Here are a couple of straightforward ways to fix this:

Method 1: Use a Formatter to Display Full Integers

You can explicitly set a formatter for the Y-axis to show complete integer values, giving you full control over label appearance:

import matplotlib.pyplot as plt

# Your original scatter plot code
x = [0,1,2,3,4,5]
y = [10001,10002,10003,10004,10005,10006]
plt.scatter(x, y)

# Force Y-axis to show full integer values
plt.gca().yaxis.set_major_formatter('{:d}'.format)

plt.show()

Method 2: Use StrMethodFormatter for More Flexibility

If you might work with decimal values later, or want finer control over formatting, use matplotlib.ticker.StrMethodFormatter:

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

x = [0,1,2,3,4,5]
y = [10001,10002,10003,10004,10005,10006]
plt.scatter(x, y)

# Format Y-axis labels as integers (adjust .0f to .2f if you need decimals)
plt.gca().yaxis.set_major_formatter(StrMethodFormatter('{x:.0f}'))

plt.show()

Method 3: Turn Off Scientific Notation Directly

You can also disable scientific notation entirely for the Y-axis with ticklabel_format:

import matplotlib.pyplot as plt

x = [0,1,2,3,4,5]
y = [10001,10002,10003,10004,10005,10006]
plt.scatter(x, y)

# Disable scientific notation for Y-axis
plt.ticklabel_format(axis='y', style='plain')

plt.show()

Bonus: Force Exact Y-Ticks

If you want the Y-axis to explicitly label every data point's value (10001 through 10006), add this line:

plt.yticks(y)

This ensures every value in your dataset is visible on the axis, which is especially helpful when your value range is this narrow.

内容的提问来源于stack exchange,提问作者lauriane.g

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 10:17:41