简体   繁体   English

如何从 mysql 通过 python 提取的数据中提取 plot 图形?

[英]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.我真的很感激任何答案,但有一点最低限度的解释。

enter image description here在此处输入图像描述

An empty plot can happen when your x and y have length 1. You can use plt.plot([x],[y], '.') to confirm.xy的长度为 1 时,可能会出现空的 plot。您可以使用plt.plot([x],[y], '.')进行确认。 This would plot the data as points这会将 plot 数据作为点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何绘制从列表列表中提取的数据? - how to plot data extracted from list of list? 有人知道如何解码从 Python 散景生成的 html 文件中提取的绘图数据点吗? - Does anybody know how to decode plot data points as extracted from a Python bokeh-generated html file? 使用文件中的数据在python中绘制图形 - Plot graph in python with data from file 如何从 python 中的 csv 获得 plot 图表 - How to plot a graph from csv in python plot 数组从命令行到图形通过 python - plot array from command line into graph through python 运行 python 脚本来监视 ftp 文件夹并绘制从每个新文件中提取的数据,因为它出现 - Run python script to monitor ftp folder and plot data extracted from each new file as it appears 如何使用python将excel中提取的数据输入到网站中? - How to input extracted data from excel into a website using python? 如何将项目从提取的数据转换为数字以在 python 中绘图? - How to turn items from extracted data to numbers for plotting in python? 使用从 txt 文件 Matplotlib Python3 中提取的数据创建水平条形图 - Creation of a Horizontal Bar Graph with data extracted from txt file Matplotlib Python3 从 sql 提取数据以使用 python 进行处理 - extracted data from sql for processing using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM