Bug in 0.9?

We had some working code were were using with 0.87, but when we try to use it
with 0.90, we get the following error:

File "/usr/local/lib/python2.4/site-packages/EEIGraph/BaseGraph.py", line 250,
in plotDate
    line = self.main_axes.plot_date( g[:,0], g[:,1] )
  
File "/usr/lib/python2.4/site-packages/matplotlib-0.90.0-py2.4-linux-i686.egg/matplotlib/axes.py",
line 2395, in plot_date
    self.xaxis_date(tz)
  
File "/usr/lib/python2.4/site-packages/matplotlib-0.90.0-py2.4-linux-i686.egg/matplotlib/axes.py",
line 1564, in xaxis_date
    formatter = AutoDateFormatter(locator)
UnboundLocalError: local variable 'locator' referenced before assignment

It happens in this function:

    def xaxis_date(self, tz=None):
        """Sets up x-axis ticks and labels that treat the x data as dates.

        tz is the time zone to use in labeling dates. Defaults to rc value.
        """

        thislocator = self.xaxis.get_major_locator()
        if not isinstance(thislocator, DateLocator):
            locator = AutoDateLocator(tz)
            self.xaxis.set_major_locator(locator)

        thisformatter = self.xaxis.get_major_formatter()
        if not isinstance(thisformatter, DateFormatter):
            formatter = AutoDateFormatter(locator)
            self.xaxis.set_major_formatter(formatter)

It seems to happen when thislocator is an AutoDateLocator, thus locator is an
AutoDateLocator, thus locator is not set, but thisformatter is a
AutoDateFormatter, which doesn't seem to satisfy isinstance(thisformatter,
DateFormatter)

I don't know enough about matplotlib internals to speculate further.

Any hints?

j

···

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
PO Box 80086 -- Fairbanks, AK 99708 -- Ph: 907-456-5581 Fax: 907-456-3111

It is a bug that is fixed in svn. The "this" part of the names is incorrect. The revised function is:

     def xaxis_date(self, tz=None):
         """Sets up x-axis ticks and labels that treat the x data as dates.

         tz is the time zone to use in labeling dates. Defaults to rc value.
         """

         locator = self.xaxis.get_major_locator()
         if not isinstance(locator, DateLocator):
             locator = AutoDateLocator(tz)
             self.xaxis.set_major_locator(locator)

         formatter = self.xaxis.get_major_formatter()
         if not isinstance(formatter, DateFormatter):
             formatter = AutoDateFormatter(locator)
             self.xaxis.set_major_formatter(formatter)

Similarly for yaxis_date.

Eric

Joshua J. Kugler wrote:

···

We had some working code were were using with 0.87, but when we try to use it with 0.90, we get the following error:

File "/usr/local/lib/python2.4/site-packages/EEIGraph/BaseGraph.py", line 250, in plotDate
    line = self.main_axes.plot_date( g[:,0], g[:,1] )
  File "/usr/lib/python2.4/site-packages/matplotlib-0.90.0-py2.4-linux-i686.egg/matplotlib/axes.py", line 2395, in plot_date
    self.xaxis_date(tz)
  File "/usr/lib/python2.4/site-packages/matplotlib-0.90.0-py2.4-linux-i686.egg/matplotlib/axes.py", line 1564, in xaxis_date
    formatter = AutoDateFormatter(locator)
UnboundLocalError: local variable 'locator' referenced before assignment

It happens in this function:

    def xaxis_date(self, tz=None):
        """Sets up x-axis ticks and labels that treat the x data as dates.

        tz is the time zone to use in labeling dates. Defaults to rc value.
        """

        thislocator = self.xaxis.get_major_locator()
        if not isinstance(thislocator, DateLocator):
            locator = AutoDateLocator(tz)
            self.xaxis.set_major_locator(locator)

        thisformatter = self.xaxis.get_major_formatter()
        if not isinstance(thisformatter, DateFormatter):
            formatter = AutoDateFormatter(locator)
            self.xaxis.set_major_formatter(formatter)

It seems to happen when thislocator is an AutoDateLocator, thus locator is an AutoDateLocator, thus locator is not set, but thisformatter is a AutoDateFormatter, which doesn't seem to satisfy isinstance(thisformatter, DateFormatter)

I don't know enough about matplotlib internals to speculate further.

Any hints?

j

Thank you! That did the trick!

j

···

On Wednesday 11 April 2007 15:49, Eric Firing wrote:

It is a bug that is fixed in svn. The "this" part of the names is
incorrect. The revised function is:

     def xaxis_date(self, tz=None):
         """Sets up x-axis ticks and labels that treat the x data as dates.

         tz is the time zone to use in labeling dates. Defaults to rc
value.
         """

         locator = self.xaxis.get_major_locator()
         if not isinstance(locator, DateLocator):
             locator = AutoDateLocator(tz)
             self.xaxis.set_major_locator(locator)

         formatter = self.xaxis.get_major_formatter()
         if not isinstance(formatter, DateFormatter):
             formatter = AutoDateFormatter(locator)
             self.xaxis.set_major_formatter(formatter)

Similarly for yaxis_date.

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
PO Box 80086 -- Fairbanks, AK 99708 -- Ph: 907-456-5581 Fax: 907-456-3111