[英]How to plot a graph from the data extracted from mysql through python?
import mysql.connector as myc
from mysql.connector import Error
import matplotlib.pyplot as plt
import pandas as pd
db = myc.connect(host='localhost',database='patients',user='root',password='root')
mc = db.cursor()
mc.execute('select count(*) from corona group by date')
for i in mc:
x=[]
x=x.append(i)
mc.execute('select distinct date from corona ')
for j in mc:
y=[]
y=y.append(j)
plt.plot([x],[y])
plt.legend()
plt.show()
this is the code we are using here for plotting a line graph.这是我们在这里用来绘制折线图的代码。 what we are expecting is that the graph should show distinct dates in ascending order.我们期望的是图表应该按升序显示不同的日期。 we wanted to plot a graph with the no.of patients that have entered that day versus the date.我们想要 plot 一个图表,其中包含当天进入的患者数量与日期的关系。 we wanted to show a gradual increase or decrease in the count.我们想要显示计数的逐渐增加或减少。 but this code does not show that (the image attached) and no error is also shown.但是这段代码没有显示(附图片),也没有显示错误。 we can't find what is wrong also.我们也找不到问题所在。 please help.请帮忙。 I would really appreciate any answer but with a little minimum explanation.我真的很感激任何答案,但有一点最低限度的解释。
An empty plot can happen when your x
and y
have length 1. You can use plt.plot([x],[y], '.')
to confirm.当x
和y
的长度为 1 时,可能会出现空的 plot。您可以使用plt.plot([x],[y], '.')
进行确认。 This would plot the data as points这会将 plot 数据作为点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.