2 回答

TA贡献1806条经验 获得超8个赞
您可以使用FuncFormatter的matplotlib.ticker更新蜱,你想对你目前的阴谋。在我下面的示例中,刻度是使用 customscientific_formatter更新的,我定义它以使用 2 个精度数字更新科学记数法中的刻度 - %2E。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
profit = pd.Series(np.random.randint(1e2, size=5))
ax = profit.plot(kind="bar")
def scientific(x, pos):
# x: tick value - ie. what you currently see in yticks
# pos: a position - ie. the index of the tick (from 0 to 9 in this example)
return '%.2E' % x
scientific_formatter = FuncFormatter(scientific)
ax.yaxis.set_major_formatter(scientific_formatter)

TA贡献1810条经验 获得超4个赞
错误是因为plt.ticklabel_format(style='plain')
默认情况下将两个轴都设置为 ,plain
而您的 xticks 是自定义的并且不能是plain
。
用于plt.ticklabel_format(axis="y", style='plain')
单独设置 y 轴。
添加回答
举报