- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们建立了一个 MySQL 数据库,其中存储了温度数据。我们现在想要检索这些数据,然后绘制它。我们所做的如下:
engine = create_engine("mysql://xxx:xxx@xxx@localhost/xxx")
conn = engine.connect()
list_temp = []
list_time = []
list_temp = pd.read_sql('SELECT temperature FROM Raw_Data WHERE topic="lpn1"', conn).astype(float).values
list_time = pd.read_sql('SELECT timestamp FROM Raw_Data WHERE topic="lpn1"', conn).astype(str).values
上面是建立与MySQL数据库的连接,然后我们从数据库中获取数据和时间戳。如果我们打印 list_temp 和 list_time,我们会看到:
[[30.4 ]
[29.71]
[29.46]
...
[20.07]
[21.05]
[21.87]]
[['2019-07-26 15:09:25']
['2019-07-26 15:24:26']
['2019-07-26 15:39:26']
...
['2019-08-20 14:07:49']
['2019-08-20 14:22:49']
['2019-08-20 14:37:49']]
这表明它们是嵌套的......
然后我们尝试通过这样做来保存绘图:
# plot
plt.plot(list_time,list_temp)
plt.gcf().autofmt_xdate()
plt.savefig('foo.png')
不幸的是,我们收到此错误:TypeError: unhashable type: 'numpy.ndarray'
当然,我们怀疑这一定是因为我们的值是嵌套的。
关于如何解决这个问题有什么想法吗?
最佳答案
list_temp 是一个只有一个元素的列表,也就是包含你的数据的列表。与 list_time 相同。所以替换这一行
plt.plot(list_time,list_temp)
用这个:
plt.plot(list_time[:,0], list_temp[:,0])
获取内部列表。
关于python - 如何在 python 中用 MySQL 检索温度和日期时间绘制一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57574381/
如何迭代(一行)分割函数给我的每个类? 我试过这个: 编辑(抱歉) $("p").attr("class").split(' ').each (function (i,n){alert(n)}
我有一条垂直线和一条水平线,当我动态调整我的 Canvas 父级时,我想调整它们的大小。 (地标) 我希望水平线始终距 Canvas 的左右边界 25 处,距底部边界 13 处。 垂直线也是如此,距上
我有一个 y 变量,我试图在图形的顶部和底部针对两个相关的 x 轴绘制它(例如 y="立方体中的事物数",x1="立方体的边长", x2="立方体的体积")。我在 numpy 数组中有 y、x1、x2
我想画一条简单的水平线,并在这条线 flex 的地方制作动画。我有这个动画的视频。你能给我一些建议如何开始以及我必须使用哪个 js/css 吗? 都是关于矩形底部的线: http://www.stop
我是一名优秀的程序员,十分优秀!