python - 如何添加matplotlib轴单位

标签 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)

情节是

enter image description here

但我希望 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()

Plot

关于python - 如何添加matplotlib轴单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57140312/

相关文章:

python - 叠加在图上的 Quiver 矢量

python - 从 Axes(或Figure)获取 QuadMesh 对象

python - 对数据点拟合更好的高斯分布?

python - 如何将一系列图像绘制到特定 map 上

python - 添加 QTextEdit 小部件作为中央小部件使主窗口不弹出,并且 showMaximize 导致计算机崩溃?

python - Airflow - 彩色记录

python - 在终端中给出导入 tfrecord 文件的正确路径

python - 是否可以在 Django 模板语言中定位 html 元素的值?

python - 特定代码行的类似装饰器的语法

python - 删除轴刻度