Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find xaxis in version 0.4.2 #271

Closed
lmadaus opened this issue Nov 29, 2016 · 7 comments
Closed

Cannot find xaxis in version 0.4.2 #271

lmadaus opened this issue Nov 29, 2016 · 7 comments
Labels
Area: Plots Pertains to producing plots Type: Bug Something is not working like it should
Milestone

Comments

@lmadaus
Copy link

lmadaus commented Nov 29, 2016

I had been successfully using the "SkewT" object in metpy to format SkewT plots in a variety of scripts. I recently upgraded to the latest metpy version (0.4.2) and all of my scripts that try making SkewT plots are now failing with an error that claims 'SkewXAxesSubplot' has no attribute 'xaxis'. I'm using Python 3.5.2/Anaconda and have matplotlib version 1.5.3. My plotting script and the full error message are shown below.

fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, rotation=45)
skew.plot(pressure, temperature, 'r')
skew.plot_dry_adiabats()
skew.plot_moist_adiabats()
skew.plot_mixing_lines()
skew.ax.set_ylim(1000, 100)

plt.show()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-27cb0bab1591> in <module>()
      1 # Create a new figure. The dimensions here give a good aspect ratio
      2 fig = plt.figure(figsize=(9, 9))
----> 3 skew = SkewT(fig, rotation=45)
      4 skew.plot(pressure, temperature, 'r')
      5 

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/metpy/plots/skewt.py in __init__(self, fig, rotation, subplot)
    228         except TypeError:
    229             subplot = (subplot,)
--> 230         self.ax = fig.add_subplot(*subplot, projection='skewx', rotation=rotation)
    231         self.ax.grid(True)
    232 

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs)
   1003                     self._axstack.remove(ax)
   1004 
-> 1005             a = subplot_class_factory(projection_class)(self, *args, **kwargs)
   1006 
   1007         self._axstack.add(key, a)

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_subplots.py in __init__(self, fig, *args, **kwargs)
     71 
     72         # _axes_class is set in the subplot_class_factory
---> 73         self._axes_class.__init__(self, fig, self.figbox, **kwargs)
     74 
     75     def __reduce__(self):

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/metpy/plots/skewt.py in __init__(self, *args, **kwargs)
    119         # This needs to be popped and set before moving on
    120         self.rot = kwargs.pop('rotation', 30)
--> 121         Axes.__init__(self, *args, **kwargs)
    122 
    123     def _init_axis(self):

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_base.py in __init__(self, fig, rect, axisbg, frameon, sharex, sharey, label, xscale, yscale, **kwargs)
    501 
    502         # this call may differ for non-sep axes, e.g., polar
--> 503         self._init_axis()
    504 
    505         if axisbg is None:

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/metpy/plots/skewt.py in _init_axis(self)
    123     def _init_axis(self):
    124         # Taken from Axes and modified to use our modified X-axis
--> 125         self.xaxis = SkewXAxis(self)
    126         self.spines['top'].register_axis(self.xaxis)
    127         self.spines['bottom'].register_axis(self.xaxis)

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axis.py in __init__(self, axes, pickradius)
    658         self._minor_tick_kw = dict()
    659 
--> 660         self.cla()
    661         self._set_scale('linear')
    662 

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axis.py in cla(self)
    742         self._set_artist_props(self.label)
    743 
--> 744         self.reset_ticks()
    745 
    746         self.converter = None

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axis.py in reset_ticks(self)
    756         cbook.popall(self.minorTicks)
    757 
--> 758         self.majorTicks.extend([self._get_tick(major=True)])
    759         self.minorTicks.extend([self._get_tick(major=False)])
    760         self._lastNumMajorTicks = 1

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/metpy/plots/skewt.py in _get_tick(self, major)
     85     """
     86     def _get_tick(self, major):
---> 87         return SkewXTick(self.axes, 0, '', major=major)
     88 
     89     def get_view_interval(self):

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axis.py in __init__(self, axes, loc, label, size, width, color, tickdir, pad, labelsize, labelcolor, zorder, gridOn, tick1On, tick2On, label1On, label2On, major)
    162         self.label2On = label2On
    163 
--> 164         self.update_position(loc)
    165 
    166     def apply_tickdir(self, tickdir):

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/matplotlib/axis.py in update_position(self, loc)
    448         if self.tick2On:
    449             self.tick2line.set_xdata((x,))
--> 450         if self.gridOn:
    451             self.gridline.set_xdata((x,))
    452         if self.label1On:

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/metpy/plots/skewt.py in gridOn(self)
     35     @property
     36     def gridOn(self):
---> 37         return (self._gridOn and transforms.interval_contains(self.get_view_interval(),
     38                                                               self.get_loc()))
     39 

/Users/lmadaus/anaconda3/lib/python3.5/site-packages/metpy/plots/skewt.py in get_view_interval(self)
     75 
     76     def get_view_interval(self):
---> 77         return self.axes.xaxis.get_view_interval()
     78 
     79 

AttributeError: 'SkewXAxesSubplot' object has no attribute 'xaxis'
@dopplershift dopplershift added Area: Plots Pertains to producing plots Type: Bug Something is not working like it should labels Nov 29, 2016
@dopplershift
Copy link
Member

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

import metpy
from metpy.plots import SkewT

print(metpy.__version__)
print(matplotlib.__version__)

pressure = np.linspace(1000, 100)
temperature = np.linspace(50, -50)

fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, rotation=45)
skew.plot(pressure, temperature, 'r')
skew.plot_dry_adiabats()
skew.plot_moist_adiabats()
skew.plot_mixing_lines()
skew.ax.set_ylim(1000, 100)

plt.show()

That version of your code runs fine for me here on 0.4.2 (against matplotlib from defaults and metpy from conda-forge). Does it fail for you? I want to make sure I have a reliable test case and that your data doesn't make the difference.

What matplotlib backend are you using?

@dopplershift
Copy link
Member

dopplershift commented Nov 29, 2016

More importantly, do you set the matplotlib rcParam axes.grid to True somewhere? If you're not sure, add print(matplotlib.rcParams['axes.grid']) somewhere near the top of the script.

@lmadaus
Copy link
Author

lmadaus commented Nov 29, 2016 via email

@dopplershift
Copy link
Member

Ok, glad to have that confirmation. I was wondering how I managed to miss this. Setting that to False is your work-around for 0.4.2.

I'll fix this up (once I figure out how to break this cycle) and get a 0.4.3 out with this and hopefully a fix for #270 this week.

@lmadaus
Copy link
Author

lmadaus commented Nov 29, 2016 via email

@dopplershift
Copy link
Member

No problem. I was really confused for a bit there wondering how the tests could have missed that!

@dopplershift dopplershift modified the milestone: 0.4.3 Nov 29, 2016
dopplershift added a commit to dopplershift/MetPy that referenced this issue Dec 12, 2016
It looks like this was fixed with earlier SkewT adjustments, but it's
still good to add a test (that failed without the fix). While we're at
it, this test also hits the path that automatically creates a new
figure.
dopplershift added a commit that referenced this issue Dec 13, 2016
It looks like this was fixed with earlier SkewT adjustments, but it's
still good to add a test (that failed without the fix). While we're at
it, this test also hits the path that automatically creates a new
figure.
@dopplershift
Copy link
Member

Fixed by 063d5b5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Plots Pertains to producing plots Type: Bug Something is not working like it should
Projects
None yet
Development

No branches or pull requests

2 participants