I have a graph within a GUI which opens with a button click. It opens from a csv file that constantly updates, hence the counting at the beginning, I wanted to limit the number of entries for the x-axis.
The plot works for the four lines however, I have been unable to refine the x axis, what I would like to do is;
- Rotate the font
- Remove the trailing zeros for the dates
- Possibly Change the Date Format to D-M-Y H:M
The Below script is what I have so far:
def open_graph():
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from dateutil import parser
from csv import reader
with open('Voltage_Readings.csv','r') as f:
data = list(reader(f))
file=open('Voltage_Readings.csv')
numlines=(len(file.readlines())-1)
start=numlines-100
end=numlines
fig=plt.figure()
ax=plt.subplot(111)
DTG = [parser.parse(i[1]) for i in data[start:end]]
Battery_Level = [i[2] for i in data[start:end]]
Gene_Supply = [i[3] for i in data[start:end]]
Solar_Supply = [i[4] for i in data[start:end]]
Wind_Supply = [i[5] for i in data[start:end]]
plt.plot(DTG, Battery_Level,'-r', label='Battery')
plt.plot(DTG, Gene_Supply,'-y', label='Gene')
plt.plot(DTG, Solar_Supply,'-b', label='Solar')
plt.plot(DTG, Wind_Supply,'-g', label='Wind')
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width *0.85, box.height])
ax.legend(bbox_to_anchor=(1, 1),loc=2)
plt.title('VOLTAGE MEASUREMENTS FROM POWER SOURCES')
plt.xlabel('Time')
plt.ylabel('Voltage')
plt.show()
I would appreciate any assistance is being able to achieve this as I am still learning.