首页 > 解决方案 > 在 y 轴上添加科学记数法会改变 matplotlib 条形图中条形的高度

问题描述

我想在 y 轴上用科学记数法制作条形图。

但是,当我使用 时 plt.ticklabel_format(axis="y", style="scientific", scilimits=(0,0), useOffset = False, useMathText=True),条形图的高度会发生变化,因此输入参数不正确。

我真的不知道为什么会这样。请参阅所附的两个图和代码。

fig = plt.figure()
# with and without below line
plt.ticklabel_format(
    axis="y", 
    style="scientific", 
    scilimits=(0,0), 
    useOffset = False, 
    useMathText=True,
)
plt.bar(x=x, height = height)
plt.xlabel('Load case no.')
plt.ylabel('Damage [-]')

plt.grid(axis="y",linestyle='--')
plt.draw()
没有科学记数法 用科学记数法
没有科学记数法(默认) 用科学记数法

标签: matplotlibbar-chart

解决方案


推荐阅读