Quick update: http://matplotlib.org/examples/api/date_demo.html and http://stackoverflow.com/questions/3677368/matplotlib-format-axis-offset-values-to-whole-numbers-or-specific-number mention something called a Formatter. DateFormatter from the first link looks like it should do what you're after (convert to a date rather than a time).
Anthony <http://stackoverflow.com/questions/3677368/matplotlib-format-axis-offset-values-to-whole-numbers-or-specific-number> On 31 August 2014 13:57, Anthony Briggs <[email protected]> wrote: > Hi Kevin, > > Looks like it's just pulling those keys from the data, so something to > convert those explicitly when you read it in would probably be the easiest > way. There might be something in the read_csv function to convert data from > a particular column, or you could try a dictionary comprehension per > station (something along the lines of station_data = {reading['DT'][:10]: > reading for reading in d[stn]}. > > You seem to have a lot of values for the same day though, so you'd either > want to grab just the minimum, or do some sort of formatting in matplotlib. > > Another method would be to find the minimum value (or minimum 3) for a > station and just report a warning if it's below a certain amount, rather > than a graph which someone has to interpret. > > Final point - having a lot of one and two character variables makes it > really hard to tell what your script is doing. > > Hope that helps, > > Anthony > > > > On 31 August 2014 11:11, Kevin Shackleton <[email protected]> wrote: > >> Hi, >> >> New to Melbourne PUG. Fairly new to Python. >> >> I have a script that interprets power levels at several automated >> surveying total stations working at a site. The idea is to show that the >> batteries have enough amp-hours to see the total station through a run of >> cloudy days. After 2 or 3 years of battery life the battery amp-hour >> capacity will have reduced to a point where the installation will run often >> out of power before the solar panels kick in each morning. In practice >> this is often affected by 3rd parties hanging extra electrical load on our >> installation. >> >> The data looks like this: >> 2014-06-16T18:40:20,HUT1,56 >> 2014-06-16T19:02:49,HUT2,15 >> 2014-06-16T20:16:12,HUT1,58 >> 2014-06-16T20:17:08,HUT2,11 >> 2014-06-16T20:51:17,HUT1,67 >> 2014-06-17T11:51:05,HUT1,100 >> 2014-06-17T11:51:07,HUT2,48 >> 2014-06-17T11:51:08,HUT3,57 >> where power level readings are coming from each of the huts (there are >> actually 4 of them) at random times and with different data densities per >> hut according to the cycle schedules. The power levels are percent. Some >> total stations report in volts but that's another problem. >> >> My script solution is: >> import pandas as pd >> import matplotlib.pyplot as plt >> df = pd.read_csv('Power_Log.csv',names=['DT','Station','Power']) >> df2=df.groupby(['Station']) # set 'Station' as the data index >> d = dict(iter(df2)) # make a dictionary including each station's data >> for stn in d.keys(): >> plt.figure() # creates a new plot canvas >> fig, ax = plt.subplots() # creates components of the plot >> ax.set_ylabel('Power (%)',fontsize=12) >> fig.subplots_adjust(bottom=0.15) >> d[stn].interpolate().plot(x='DT',y='Power',rot=15,title='Power Level: >> ' + stn) >> ax.set_xlabel('Date-Time',fontsize=12) >> plt.savefig('Station_Power_' + stn + '.png') >> >> Possibly a bit wasteful going from dataframe to dataframe to dictionary. >> >> This code knocks out nice graphs, except for one thing - the x ticks are >> at unrounded positions and therefore have long labels. >> >> I'm getting nowhere with set_major_formatter and autofmt_xdate methods to >> try to set the ticks to rounded days. >> >> And brilliant ideas here? >> >> Thanks, >> >> Kevin. >> >> _______________________________________________ >> melbourne-pug mailing list >> [email protected] >> https://mail.python.org/mailman/listinfo/melbourne-pug >> >> >
_______________________________________________ melbourne-pug mailing list [email protected] https://mail.python.org/mailman/listinfo/melbourne-pug
