[Matplotlib-users] Totaly new to matplotlib

Paul Hobson pmhobson at gmail.com
Sat Feb 6 00:57:51 EST 2016


Looks like you should set the y-formatter in a similar fashion as you do
the the x-formatter:

hrmin_fmt = dates.DateFormatter('%H %M')
ax.yaxis.set_major_formatter(hrmin_fmt)

On Fri, Feb 5, 2016 at 10:53 AM, Stevo <stm6386 at gmail.com> wrote:

> Guys,
> This is where I am now -
> code
> def plot_durations(self,starts, stops, ax , **kwargs):
>         if ax is None:
>             ax = plt.gca()
>         # Make the default alignment center, unless specified otherwise
>         kwargs['align'] = kwargs.get('align', 'center')
>
>         # Convert things to matplotlib's internal date format...
>         starts, stops = mpl.dates.date2num(starts),
> mpl.dates.date2num(stops)
>
>         # Break things into start days and start times
>         start_times = starts % 1
>         start_days = starts - start_times
>         durations = stops - starts
>         start_times += int(starts[0]) # So that we have a valid date...
>
>         # Plot the bars
>         artist = ax.bar(start_days, durations, bottom=start_times,
> **kwargs)
>
>         # Tell matplotlib to treat the axes as dates...
>         hfmt = dates.DateFormatter('%b %d')
>         ax.xaxis.set_major_formatter(hfmt)
>         ax.xaxis.set_major_locator(plt.MultipleLocator(1.0)) #a tick mark a
> day
>         ax.yaxis_date()
>         ax.figure.autofmt_xdate()
>         ax.invert_yaxis()
>         plt.subplots_adjust (left = 0.1, bottom = 0.10, right = 0.97, top =
> 0.97, wspace = 0.20, hspace = 0.2)
>         plt.show()
> code
>
> But for some reason I get inconsistent results for the y axis .....
> <http://matplotlib.1069221.n5.nabble.com/file/n46719/figure_1-1.png>
> <http://matplotlib.1069221.n5.nabble.com/file/n46719/figure_4.png>
> I would prefer just hh:mm format if I could set it but have no idea why it
> would the extra 0's ... the script wasnt restarted or anything just another
> set of data used, the data looked identical in each case so I have no idea
> what the change is caused by .... selecting and reselecting data just gave
> the same results.
> I could show the whole script if it helps but it gets quite complex.
>
> Just learning and  loving Python
> Stevo
>
>
>
> --
> View this message in context:
> http://matplotlib.1069221.n5.nabble.com/Totaly-new-to-matplotlib-tp46682p46719.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160205/0c8dcfa6/attachment.html>


More information about the Matplotlib-users mailing list