<分区>
我有以下代码:
import matplotlib.pyplot as plt
x = [i * 2872155 for i in range(1, 11)]
y = [0.219, 0.402, 0.543, 0.646,0.765, 0.880,1.169, 1.358,1.492,1.611]
plt.plot(x, y)
情节是
但我希望 y 标签为 0.2s、0.4s、0.6s。 我该怎么做?
标签 python matplotlib
<分区>
我有以下代码:
import matplotlib.pyplot as plt
x = [i * 2872155 for i in range(1, 11)]
y = [0.219, 0.402, 0.543, 0.646,0.765, 0.880,1.169, 1.358,1.492,1.611]
plt.plot(x, y)
情节是
但我希望 y 标签为 0.2s、0.4s、0.6s。 我该怎么做?
最佳答案
试试这个:
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
x = [i * 2872155 for i in range(1, 11)]
y = [0.219, 0.402, 0.543, 0.646,0.765, 0.880,1.169, 1.358,1.492,1.611]
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%.1f s'))
plt.plot(x, y)
plt.show()
关于python - 如何添加matplotlib轴单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57140312/