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



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

John,

John Hunter wrote:
On Fri, Sep 18, 2009 at 4:39 AM, Werner F. Bruhin <werner.bru...@free.fr> 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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users



# -*- coding: utf-8 -*-#
#!/usr/bin/env python
"""
An example of how to use wx or wxagg in an application with the new
toolbar - comment out the setA_toolbar line for no toolbar
"""

import datetime

from numpy import arange, sin, pi

import matplotlib
print matplotlib.__version__

# uncomment the following to use wx rather than wxagg
#matplotlib.use('WX')
#from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas

# comment out the following to use wx rather than wxagg
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

from matplotlib.backends.backend_wx import NavigationToolbar2Wx

from matplotlib.figure import Figure

from matplotlib.dates import YearLocator, MonthLocator, DateFormatter, WeekdayLocator

from matplotlib.dates import MONDAY, SATURDAY

from matplotlib.finance import quotes_historical_yahoo


import wx

print wx.__version__

class CanvasFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self,None,-1,
                         'CanvasFrame',size=(550,350))

        self.SetBackgroundColour(wx.NamedColor("WHITE"))

        self.figure = Figure()
        self.canvas = FigureCanvas( self, -1, self.figure)

        date1 = datetime.date( 2002, 1, 5 )
        date2 = datetime.date( 2003, 12, 1 )
        
        # every monday
        mondays   = WeekdayLocator(MONDAY)
        
        # every 3rd month
        months    = MonthLocator(range(1,13), bymonthday=1, interval=3)
        monthsFmt = DateFormatter("%b '%y")
        
        
        quotes = quotes_historical_yahoo('INTC', date1, date2)
        if not quotes:
            print 'Found no quotes'
            raise SystemExit
        
        dates = [q[0] for q in quotes]
        opens = [q[1] for q in quotes]
        
        self.axes = self.figure.add_subplot(111)
        # following line is commented to force the exception
##        self.axes.plot_date(dates, opens, '-')

        self.axes.autoscale_view()
        self.axes.grid(True)

        yearLoc = YearLocator()
        yearFmt = DateFormatter('%Y')
        # comment the following line not to get the exeception
        self.axes.xaxis.set_major_formatter(yearFmt)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.add_toolbar()  # comment this out for no toolbar


    def add_toolbar(self):
        self.toolbar = NavigationToolbar2Wx(self.canvas)
        self.toolbar.Realize()
        if wx.Platform == '__WXMAC__':
            # Mac platform (OSX 10.3, MacPython) does not seem to cope with
            # having a toolbar in a sizer. This work-around gets the buttons
            # back, but at the expense of having the toolbar at the top
            self.SetToolBar(self.toolbar)
        else:
            # On Windows platform, default window size is incorrect, so set
            # toolbar width to figure width.
            tw, th = self.toolbar.GetSizeTuple()
            fw, fh = self.canvas.GetSizeTuple()
            # By adding toolbar in sizer, we are able to put it at the bottom
            # of the frame - so appearance is closer to GTK version.
            # As noted above, doesn't work for Mac.
            self.toolbar.SetSize(wx.Size(fw, th))
            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        # update the axes menu on the toolbar
        self.toolbar.update()


    def OnPaint(self, event):
        self.canvas.draw()

class App(wx.App):

    def OnInit(self):
        'Create the main window and insert the custom frame'
        frame = CanvasFrame()
        frame.Show(True)

        return True

app = App(0)
app.MainLoop()
------------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to