如何在matlotlib图形上显示数据(y轴值)? 我找到了这个相关的post,我尝试了建议的解决方案,但它在这里不起作用,至少我想不出来。如果你能帮忙,我将不胜感激。谢谢。你知道吗
这里我试着用三个不同的图来绘制y值(mean,aver,dist)与时间的关系。你知道吗
这是我的密码:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import mysql.connector
from matplotlib import style
from matplotlib.pyplot import figure
from matplotlib import pyplot
conn = mysql.connector.MySQLConnection(user='root', password='', host='127.0.0.1', database='DB')
cursor = conn.cursor()
sql = "SELECT Time, mean, Aver, Dist FROM datatb order by Time Desc limit 100"
cursor.execute(sql)
result = cursor.fetchall()
df = pd.DataFrame(list(result),columns=["Time","Mean","Aver","Dist"])
plt.figure(num=None, figsize=(15, 12), dpi=150, facecolor='w', edgecolor='k')
plt.subplot(2,1,1)
plt.title('Mean')
plt.plot(df['Time'], df["Mean"],'o-', c='blue',label=r'$Mean$')
plt.legend(loc='best')
ax = plt.gca()
ax.invert_xaxis()
plt.figure(num=None, figsize=(15, 12), dpi=150, facecolor='w', edgecolor='k')
plt.subplot(2,1,2)
plt.title('Aver')
plt.plot(df['Time'], df["Aver"],'o-', c='green', label=r'$Aver$')
plt.legend(loc='best')
ax = plt.gca()
ax.invert_xaxis()
plt.figure(num=None, figsize=(15, 12), dpi=150, facecolor='w', edgecolor='k')
plt.subplot(2,1,2)
plt.title('Dist')
plt.plot(df['Time'], df["Dist"], 'o-', c='brown', label=r'$Dist$')
plt.legend(loc='best')
ax = plt.gca()
ax.invert_xaxis()
conn.close()
cursor.close()
我的情节是这样的:
使用
annotate
:示例:
现在,用
df['Time']
和df["Mean"]
替换x
和y
。你知道吗相关问题 更多 >
编程相关推荐