首页 > 解决方案 > pyplot总是绘制直线

问题描述

我有这段代码可以使用 matplotlib 在 python 中绘制一些数据:

import matplotlib.pyplot as plt
x=[1,2,5]
y=[2,4,1]
plt.plot(x,y)
plt.show()

这完美地绘制,这是结果:

pyplot 示例工作

在我的另一个代码中,我有这个值:

x = [0 1 2 3 4 5 6 7 8 9]

y = ['7065' '2604' '2003' '1939' '1746' '1578' '1472' '1414' '1320' '1288']

现在,我得到的是:

pyplot工作乱码

条形图,也是一样的,这里:

条形图错误

它总是给我一条直线,这是为什么呢?

值在Python Shell中可见

标签: pythonpython-3.xmatplotlib

解决方案


我写了这个:

y = list(map(int, y))

str列表变成了int列表。


推荐阅读