Note that there are some explanatory texts on larger screens.

plurals
  1. POMatplotlib - Float to HH:MM
    primarykey
    data
    text
    <p>Evening all, I'm trying to produce yaxis as HH:MM. I thought using the two below #'d lines would do the trick but they produce the error which can be seen below. Any help greatly appreciated.</p> <pre><code>x = ['23/09/2013', '24/09/2013', '25/09/2013', '26/09/2013', '27/09/2013'] ytemp = ['03:04:54', '03:26:29', '03:41:13', '03:20:07', '01:01:04'] import datetime from matplotlib.dates import date2num, MINUTES_PER_DAY, SEC_PER_DAY, DateFormatter import pylab as p # function: Represent a string time in seconds. def convert(s): h,m,s = map(float, s.split(':')) return h/24. + m/MINUTES_PER_DAY + s/SEC_PER_DAY for i in ytemp: y.append(convert(str(i))) fig = p.figure() ax = fig.add_subplot(111) N = len(y) ind = range(N) ax.bar(ind, y, facecolor='#777777', align='center') #ax.yaxis_date() #ax.yaxis.set_major_formatter(DateFormatter('%H:%M')) ax.set_ylabel('Idle Time') ax.set_title(totalidle[1][0],fontstyle='italic') ax.set_xticks(ind) ax.set_xticklabels([x[0], x[1], x[2], x[3], x[4]]) fig.autofmt_xdate() p.show() </code></pre> <p>y is [0.12840277777777775, 0.1433912037037037, 0.15362268518518518, 0.13896990740740742, 0.0424074074074074]</p> <p>the error is:</p> <pre class="lang-none prettyprint-override"><code>Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:\Python33\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 276, in resize self.show() File "C:\Python33\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 348, in draw FigureCanvasAgg.draw(self) File "C:\Pytho Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:\Python33\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 276, in resize self.show() File "C:\Python33\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 348, in draw FigureCanvasAgg.draw(self) File "C:\Python33\lib\site-packages\matplotlib\backends\backend_agg.py", line 451, in draw self.figure.draw(self.renderer) File "C:\Python33\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python33\lib\site-packages\matplotlib\figure.py", line 1035, in draw func(*args) File "C:\Python33\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python33\lib\site-packages\matplotlib\axes.py", line 2088, in draw a.draw(renderer) File "C:\Python33\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 1092, in draw ticks_to_draw = self._update_ticks(renderer) File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 946, in _update_ticks tick_tups = [t for t in self.iter_ticks()] File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 946, in &lt;listcomp&gt; tick_tups = [t for t in self.iter_ticks()] File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 890, in iter_ticks majorLocs = self.major.locator() File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 802, in __call__ self.refresh() File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 819, in refresh dmin, dmax = self.viewlim_to_dt() File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 564, in viewlim_to_dt return num2date(vmin, self.tz), num2date(vmax, self.tz) File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 311, in num2date return _from_ordinalf(x, tz) File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 214, in _from_ordinalf dt = datetime.datetime.fromordinal(ix) ValueError: ordinal must be &gt;= 1n33\lib\site-packages\matplotlib\backends\backend_agg.py", line 451, in draw self.figure.draw(self.renderer) File "C:\Python33\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python33\lib\site-packages\matplotlib\figure.py", line 1035, in draw func(*args) File "C:\Python33\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python33\lib\site-packages\matplotlib\axes.py", line 2088, in draw a.draw(renderer) File "C:\Python33\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 1092, in draw ticks_to_draw = self._update_ticks(renderer) File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 946, in _update_ticks tick_tups = [t for t in self.iter_ticks()] File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 946, in &lt;listcomp&gt; tick_tups = [t for t in self.iter_ticks()] File "C:\Python33\lib\site-packages\matplotlib\axis.py", line 890, in iter_ticks majorLocs = self.major.locator() File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 802, in __call__ self.refresh() File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 819, in refresh dmin, dmax = self.viewlim_to_dt() File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 564, in viewlim_to_dt return num2date(vmin, self.tz), num2date(vmax, self.tz) File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 311, in num2date return _from_ordinalf(x, tz) File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 214, in _from_ordinalf dt = datetime.datetime.fromordinal(ix) ValueError: ordinal must be &gt;= 1 </code></pre> <hr>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload