【发布时间】:2020-03-30 01:44:23
【问题描述】:
我正在创建一个绘图(在 colab 工作表中)并希望 y 刻度标签不使用科学记数法。 ticklabel_format 对最终图形没有任何影响。 y 轴标签仍显示为 10^3 而不是 1000。如何格式化 y 刻度标签以不使用科学记数法? 这是我的代码
import matplotlib.pyplot as plt
plt.ticklabel_format(style='plain', axis='y')
plt.plot(Cd_rank,Cd_raw,linewidth=4)
plt.plot(Cd_rank,Cd_sed,linewidth=4)
plt.plot(Cd_rank,Cd_filter,linewidth=4)
plt.plot([0,1],[0.3,0.3],linewidth=4)
plt.plot([0,1],[5,5],linewidth=4)
plt.ylabel('Turbidez (UTN)')
plt.xlabel('Datos ordenados')
plt.yscale('log')
plt.legend(['Agua cruda','Decantada','Filtrada','Norma EPA','Norma ENACAL'])
【问题讨论】:
-
plt.gca().yaxis.set_major_formatter( matplotlib.ticker.ScalarFormatter()) -
我收到此错误:AttributeError: module 'matplotlib.pyplot' has no attribute 'ticker'。我用 plt 替换了 matplotlib。
-
好吧,你需要
matplotlib.ticker,因为plt.ticker不存在。添加import matplotlib(同时保留import matplotlib.pyplot as plt)。 -
我已经添加了 matplotlib 导入。谢谢!我假设我需要添加类似
plt.gca().yaxis.set_major_formatter( matplotlib.ticker.ScalarFormatter(style='plain', axis='y'))的内容,因为plt.gca().yaxis.set_major_formatter( matplotlib.ticker.ScalarFormatter())似乎没有做任何事情。我怀疑我遗漏了一些明显的东西。
标签: matplotlib