[melbourne-pug] Rounded-value ticks on X axis

Kevin Shackleton krshackleton at gmail.com
Wed Sep 3 04:29:10 CEST 2014


Thanks for that Tennessee.  Yes it did pip install.  I will try it out this
evening when I don't have distraction like a job . .

And thanks for the comment on pandas.  It's handy to take a hint on when
it's worth persevering to find the right syntax and when it's not.

Regards,

Kevin


On 3 September 2014 10:21, Tennessee Leeuwenburg <tleeuwenburg at gmail.com>
wrote:

> Hi Kevin,
>
> I have taken to using the Python port of ggplot, available at
> http://ggplot.yhathq.com/ . I think it's on pip also. It takes pandas
> dataframes just fine and provides a syntactically shorter route to graph
> tweaking. It's not perfect, but it solved my problems more easily than
> getting into the guts of matplotlib. (it is built on top of matplotlib so
> you can provide mpl tweaks onto the graphs it produces if you really need
> to). Pandas is not really a complete solution for graphing IMO.
>
> Feel free to share some gists of what you are trying to to, I'm happy to
> try and help out a little.
>
> Cheers,
> -T
>
>
> On 31 August 2014 16:31, Kevin Shackleton <krshackleton at gmail.com> wrote:
>
>> Unfortunately these matplotlib methods expect the data to be float, where
>> using pandas I am able to parse and handle the time series data as
>> datetime.  But graphing in pandas does not seem to inherit all the
>> matplotlib methods (I suppose that would be a mammoth task, including all
>> the method overlays).  I'm forming the opinion that I either do the job in
>> numpy/matplotlib with extra code to sculpt the exact format I want or I go
>> the concise and elegant pandas way and live with the loss of control of the
>> x axis.
>>
>> Thanks,
>>
>> Kevin
>>
>>
>> On 31 August 2014 12:01, Anthony Briggs <anthony.briggs at gmail.com> wrote:
>>
>>> 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 <anthony.briggs at gmail.com>
>>> 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 <krshackleton at gmail.com>
>>>> 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
>>>>> melbourne-pug at python.org
>>>>> https://mail.python.org/mailman/listinfo/melbourne-pug
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> melbourne-pug mailing list
>>> melbourne-pug at python.org
>>> https://mail.python.org/mailman/listinfo/melbourne-pug
>>>
>>>
>>
>> _______________________________________________
>> melbourne-pug mailing list
>> melbourne-pug at python.org
>> https://mail.python.org/mailman/listinfo/melbourne-pug
>>
>>
>
>
> --
> --------------------------------------------------
> Tennessee Leeuwenburg
> http://myownhat.blogspot.com/
> "Don't believe everything you think"
>
> _______________________________________________
> melbourne-pug mailing list
> melbourne-pug at python.org
> https://mail.python.org/mailman/listinfo/melbourne-pug
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/melbourne-pug/attachments/20140903/c8dea052/attachment.html>


More information about the melbourne-pug mailing list