我试图在matplotlib子地块环境中将格式设置为两个十进制数.不幸的是,我不知道如何解决这项任务.

为了防止在y轴上使用科学符号,我使用了ScalarFormatter(useOffset=False),你可以在下面的代码片段中看到.我认为我的任务应该通过向使用的格式化程序传递更多选项/参数来解决.然而,我在matplotlib的文档中找不到任何提示.

如何设置两个十进制数字或无(两种情况都需要)?很遗憾,我无法提供样本数据.


--片段--

f, axarr = plt.subplots(3, sharex=True)

data = conv_air
x = range(0, len(data))

axarr[0].scatter(x, data)
axarr[0].set_ylabel('$T_\mathrm{air,2,2}$', size=FONT_SIZE)
axarr[0].yaxis.set_major_locator(MaxNLocator(5))
axarr[0].yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
axarr[0].tick_params(direction='out', labelsize=FONT_SIZE)
axarr[0].grid(which='major', alpha=0.5)
axarr[0].grid(which='minor', alpha=0.2)

data = conv_dryer
x = range(0, len(data))

axarr[1].scatter(x, data)
axarr[1].set_ylabel('$T_\mathrm{dryer,2,2}$', size=FONT_SIZE)
axarr[1].yaxis.set_major_locator(MaxNLocator(5))
axarr[1].yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
axarr[1].tick_params(direction='out', labelsize=FONT_SIZE)
axarr[1].grid(which='major', alpha=0.5)
axarr[1].grid(which='minor', alpha=0.2)

data = conv_lambda
x = range(0, len(data))

axarr[2].scatter(x, data)
axarr[2].set_xlabel('Iterationsschritte', size=FONT_SIZE)
axarr[2].xaxis.set_major_locator(MaxNLocator(integer=True))
axarr[2].set_ylabel('$\lambda$', size=FONT_SIZE)
axarr[2].yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
axarr[2].yaxis.set_major_locator(MaxNLocator(5))
axarr[2].tick_params(direction='out', labelsize=FONT_SIZE)
axarr[2].grid(which='major', alpha=0.5)
axarr[2].grid(which='minor', alpha=0.2)

推荐答案

参见generalspecifically中的相关文档

from matplotlib.ticker import FormatStrFormatter

fig, ax = plt.subplots()

ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))

在此处输入图像描述

Python-3.x相关问答推荐

背包问题-如何减少内存使用

TypeError:&Quot;Value&Quot;参数必须是标量、Dict或Series,但您传递了&Quot;Index&Quot;

丢弃重复的索引,并在多索引数据帧中保留一个

被多个\n拆分并保留

如何强调您正在寻求以 pandas 数据帧的另一列为条件的差异?

Django中自动设置/更新字段

两个 y 轴在零处对齐的 plotly barplot

Django - ValueError:无法将字符串转换为浮点数:''

如何转置和 Pandas DataFrame 并命名新列?

Python3:是否可以将变量用作函数调用的一部分

Python:如何在Pandas 的 .agg 函数中使用 value_counts()?

如何在数据['column']中的'string'等条件下应用pandas

具有函数值的 Python 3 枚举

Python 3.9.8 使用 Black 并导入 `typed_ast.ast3` 失败

Jupyter Notebook - 在函数内绘图 - 未绘制图形

为什么等效的 Python 代码要慢得多

从大字典中弹出 N 项的最快方法

在 ubuntu 20.04 中安装 libpq-dev 时出现问题

python判断一个方法是否被调用而不模拟它

如何强制 Sphinx 使用 Python 3.x 解释器