does mpl.canvas has a flag "needsdrawing"?

I have multiple canvas and sometimes one or more might have nothing to draw (no data).

Currently I just call.

canvas.draw()
canvas.Refresh()

for each of the canvas, but this gives me an error if there is no data.

Is there a built-in flag I can check before calling draw? Or do I have to keep create my own?

Werner

PS
If it is of any help, I get this (also I have mpl.verbose.level = u'silent':

C:\Python25\lib\site-packages\matplotlib\axes.py:3996: UserWarning: No labeled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labeled objects found. "

And here is the traceback.
Traceback (most recent call last):
  File "C:\Dev\twcbBranchv31\Program\panelstats.py", line 178, in DoRefresh
    self.RefreshAllGraphs()
  File "C:\Dev\twcbBranchv31\Program\panelstats.py", line 313, in RefreshAllGraphs
    self.priceChangeP.canvas.draw()
  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_wxagg.py", line 59, in draw
    FigureCanvasAgg.draw(self)
  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 314, in draw
    self.figure.draw(self.renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 774, in draw
    for a in self.axes: a.draw(renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1721, in draw
    a.draw(renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "C:\Python25\Lib\site-packages\matplotlib\axis.py", line 736, in draw
    for tick, loc, label in self.iter_ticks():
  File "C:\Python25\Lib\site-packages\matplotlib\axis.py", line 677, in iter_ticks
    majorLocs = self.major.locator()
  File "C:\Python25\Lib\site-packages\matplotlib\dates.py", line 754, in __call__
    dmin, dmax = self.viewlim_to_dt()
  File "C:\Python25\Lib\site-packages\matplotlib\dates.py", line 454, in viewlim_to_dt
    return num2date(vmin, self.tz), num2date(vmax, self.tz)
  File "C:\Python25\Lib\site-packages\matplotlib\dates.py", line 249, in num2date
    if not cbook.iterable(x): return _from_ordinalf(x, tz)
  File "C:\Python25\Lib\site-packages\matplotlib\dates.py", line 170, in _from_ordinalf
    dt = datetime.datetime.fromordinal(ix)
ValueError: ordinal must be >= 1

There is no such flag, but you should not get an error on drawing an
empty figure or one that doesn't "need" to be drawn. Can you post
example code that produces the error?

JDH

···

On Fri, Sep 18, 2009 at 4:39 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:

I have multiple canvas and sometimes one or more might have nothing to
draw (no data).

Currently I just call.

canvas.draw()
canvas.Refresh()

for each of the canvas, but this gives me an error if there is no data.

Is there a built-in flag I can check before calling draw? Or do I have
to keep create my own?

John,

John Hunter wrote:

···

On Fri, Sep 18, 2009 at 4:39 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:
  

I have multiple canvas and sometimes one or more might have nothing to
draw (no data).

Currently I just call.

canvas.draw()
canvas.Refresh()

for each of the canvas, but this gives me an error if there is no data.

Is there a built-in flag I can check before calling draw? Or do I have
to keep create my own?
    
There is no such flag, but you should not get an error on drawing an
empty figure or one that doesn't "need" to be drawn. Can you post
example code that produces the error?
  

I narrowed it down to one line of code, if I comment the following line
then the error goes away.

        axes.xaxis.set_major_formatter(yearFmt)

Is this enough for you? Or do you like some runnable code?

Werner

We want a complete, free standing example that exposes the bug, with any additional info like mpl backend and version number.

···

On Sep 18, 2009, at 7:43 AM, "Werner F. Bruhin" <werner.bruhin@...185...> wrote:

John,

John Hunter wrote:

On Fri, Sep 18, 2009 at 4:39 AM, Werner F. Bruhin <werner.bruhin@...185... >> > wrote:

I have multiple canvas and sometimes one or more might have nothing to
draw (no data).

Currently I just call.

canvas.draw()
canvas.Refresh()

for each of the canvas, but this gives me an error if there is no data.

Is there a built-in flag I can check before calling draw? Or do I have
to keep create my own?

There is no such flag, but you should not get an error on drawing an
empty figure or one that doesn't "need" to be drawn. Can you post
example code that produces the error?

I narrowed it down to one line of code, if I comment the following line
then the error goes away.

       axes.xaxis.set_major_formatter(yearFmt)

Is this enough for you? Or do you like some runnable code?

Werner

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

John Hunter wrote:

We want a complete, free standing example that exposes the bug, with any additional info like mpl backend and version number.

matplotlib: 0.99.0
wx.Python: 2.8.10.1 (unicode on Win Vista)
Python 2.5.4

If I comment line 78 then the exception goes away. The attached code does not use, but the exception is the same as I get in my code when I call draw.

Hope this helps
Werner

drawexception2.py (3.67 KB)

···

On Sep 18, 2009, at 7:43 AM, "Werner F. Bruhin" > <werner.bruhin@...185...> wrote:

John,

John Hunter wrote:

On Fri, Sep 18, 2009 at 4:39 AM, Werner F. Bruhin >>> <werner.bruhin@...185...> wrote:

I have multiple canvas and sometimes one or more might have nothing to
draw (no data).

Currently I just call.

canvas.draw()
canvas.Refresh()

for each of the canvas, but this gives me an error if there is no data.

Is there a built-in flag I can check before calling draw? Or do I have
to keep create my own?

There is no such flag, but you should not get an error on drawing an
empty figure or one that doesn't "need" to be drawn. Can you post
example code that produces the error?

I narrowed it down to one line of code, if I comment the following line
then the error goes away.

       axes.xaxis.set_major_formatter(yearFmt)

Is this enough for you? Or do you like some runnable code?

Werner

------------------------------------------------------------------------------

Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks -- when posting a bug, please consider taking the time to make
a *minimal* example. Ie, there is a lot of wx cruft in the example,
as well as a lot of stuff that is created but not used (various
tickers, locators and datetime instances). We have to then filter
this down to the core bug to see if it is real. In this case it is.
But we get 1000 emails a month in addition to having to work on normal
mpl releases and development so we can use all the help we can get.

Here is my version of a minimal example, tested and failing on the
release branch and svn HEAD. I've filed a bug report at
https://sourceforge.net/tracker/?func=detail&aid=2861426&group_id=80706&atid=560720
and committed a unit test with a knownfailure decorator

    import matplotlib.dates as dates

    fig = plt.figure()
    ax = fig.add_subplot(111)

    yearFmt = dates.DateFormatter('%Y')
    ax.xaxis.set_major_formatter(yearFmt)

    fig.savefig('empty_date_bug')

That much more clearly shows where the problem is, doesn't require a
developer to have an optionaol backend installed, etc.

Thanks for the report and the test case.

JDH

···

On Fri, Sep 18, 2009 at 8:15 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:

John Hunter wrote:

We want a complete, free standing example that exposes the bug, with any
additional info like mpl backend and version number.

John Hunter wrote:

···

On Fri, Sep 18, 2009 at 8:15 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:
  

John Hunter wrote:
    

We want a complete, free standing example that exposes the bug, with any
additional info like mpl backend and version number.
      
Thanks -- when posting a bug, please consider taking the time to make
a *minimal* example.

Sorry about that - was a bit in a hurry, but that is no excuse!

Will do better next time.

Thanks for anyhow having taken the time to look at it and to distill it down.

Werner

My guess is that the error happens when the matplotlib tries to format
the date ticklabels when the xlim is not correctly set, i.e., [0, 1]
in the example. But, I'm not sure what is the best approach here.

Werner, if there is nothing to draw (i,e, xlim is [0,1]), change the
xlim to some arbitrary range that is greater than 1 (e.g, [1,2]). For
example, in your code, you may do something like following after
calling the autoscale_view().

        self.axes.autoscale_view()
        if self.axes.get_xlim()[0] < 1:
            self.axes.set_xlim(dates[0], dates[-1])

Regards,

-JJ

···

On Fri, Sep 18, 2009 at 11:41 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:

John Hunter wrote:

On Fri, Sep 18, 2009 at 8:15 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:

John Hunter wrote:

We want a complete, free standing example that exposes the bug, with any
additional info like mpl backend and version number.

Thanks -- when posting a bug, please consider taking the time to make
a *minimal* example.

Sorry about that - was a bit in a hurry, but that is no excuse!

Will do better next time.

Thanks for anyhow having taken the time to look at it and to distill it
down.

Werner

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi Jae-Joon,

Jae-Joon Lee wrote:

My guess is that the error happens when the matplotlib tries to format
the date ticklabels when the xlim is not correctly set, i.e., [0, 1]
in the example. But, I'm not sure what is the best approach here.

Werner, if there is nothing to draw (i,e, xlim is [0,1]), change the
xlim to some arbitrary range that is greater than 1 (e.g, [1,2]). For
example, in your code, you may do something like following after
calling the autoscale_view().
  

Thanks for the tip. I have in the mean time reorganized my code and I
am just bypassing the problematic code if there is nothing to draw.

Werner