在Python中绘图时设置y轴

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

我正在使用 matplotlib 在 python 中绘图。默认设置是:

plt.ticklabel_format(style='sci')

我需要它,但乘法必须与沿 y 轴显示的每个数字相反。就像图片上一样: ---->

python matplotlib
1个回答
0
投票

@Ffisegydd的答案对于我来说仍然适用于 python 3.11.7。他使用

import matplotlib.ticker as mtick
ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2e'))
。将
.2e
替换为您喜欢的任何内容(请参阅格式文档)。这会给你这样的东西

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick

x = np.linspace(0,1,1000)
y = np.linspace(0,1e6,1000)

fig = plt.figure(clear='True')
ax = fig.add_subplot(111)

ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2e'))
ax.plot(x,y)

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