How can I display the data(y axis values) on the matlotlib graph? I found this related post, I tried suggested solution but it doesn't work here, at least I couldn't figure it out. I'd appreciate if you can help. thanks.
What I try to do here is to plot the y values (mean,aver,dist) against time in three different plots.
Here is my code:
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()
My plot looks like this: