如何添加matplotlib轴单位

pet*_*ang 5 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)
Run Code Online (Sandbox Code Playgroud)

情节是

在此输入图像描述

但我希望 y 标签类似于 0.2s、0.4s、0.6s。我怎样才能做到这一点?

Car*_*ten 6

尝试这个:

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()
Run Code Online (Sandbox Code Playgroud)

阴谋