Matplotbib-PercentFormatter-如何缩放y轴并保存绘图?

时间:2020-03-09 09:26:42

标签: python-3.x matplotlib

我正在苦苦挣扎的两个快速问题。 1.如何缩放PercentFormatter,我要将y轴设置为0到100%。没有PercentFormatter,我可以做到这一点,但是必须有一种包含它的方法,对吗? 2. saveplot方法剪切x标签。我该如何预防?

fig, ax = plt.subplots()
ax.bar(df['ErrorNames'], df["Frequency"], color="C0")
ax.set_xticklabels(df['ErrorNames'], rotation=90 ) ;


ax.set_ylabel('Error Frequency')
ax2 = ax.twinx()
ax2.set_ylabel('Accumulated Percentage of Frequency')
ax2.plot(df['ErrorNames'], df["cumpercentage"], color="C1", marker="D", ms=7)
ax2.yaxis.set_major_formatter(PercentFormatter())
ax.tick_params(axis="y", colors="C0")
ax2.tick_params(axis="y", colors="C1")
plt.savefig('Pareto')
plt.show()

Pareto Chart

0 个答案:

没有答案