python - pyplot总是绘制直线
问题描述
我有这段代码可以使用 matplotlib 在 python 中绘制一些数据:
import matplotlib.pyplot as plt
x=[1,2,5]
y=[2,4,1]
plt.plot(x,y)
plt.show()
这完美地绘制,这是结果:
在我的另一个代码中,我有这个值:
x = [0 1 2 3 4 5 6 7 8 9]
y = ['7065' '2604' '2003' '1939' '1746' '1578' '1472' '1414' '1320' '1288']
现在,我得到的是:
条形图,也是一样的,这里:
它总是给我一条直线,这是为什么呢?
值在Python Shell中可见
解决方案
我写了这个:
y = list(map(int, y))
str
列表变成了int
列表。
推荐阅读
- javascript - jQuery .load() 不适用于 https:// 连接
- reactjs - 不能将 Leaflet 与 NextJS 一起使用
- c# - MassTransit - 等待所有活动完成,然后继续处理
- javascript - TypeError:无法读取未定义的属性'$http' - VUEJS
- python - 检测视频流中的某个对象
- javascript - 如何使用原始 javascript 在下拉框中显示基于 div>a 的子元素文本,如 select>option 结构
- java - java中单链表的赋值
- android - 三星 Galaxy Note 5 上的持续错误
- javascript - createStore 与 combineReducers 和 applyMiddleware 没有第二个参数
- python - 使用 Automator 运行 Python 脚本 // 为什么它仅在我包含 export PATH=/usr/local/bin:$PATH 时才有效,这是什么意思?