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

2D plot fails when passing a WCSAxes #192

Closed
wtbarnes opened this issue Aug 8, 2019 · 3 comments · Fixed by #204
Closed

2D plot fails when passing a WCSAxes #192

wtbarnes opened this issue Aug 8, 2019 · 3 comments · Fixed by #204
Assignees
Milestone

Comments

@wtbarnes
Copy link
Member

wtbarnes commented Aug 8, 2019

Description

When an axis is passed to NDCube.plot, an UnboundLocalErrror is thrown. This appears to be because ax is never actually set if axes is not None in _plot_2D_cube

Expected behavior

A 2D plot.

Actual behavior

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-50-663bc3b9d2f3> in <module>
      1 fig = plt.figure()
      2 ax = fig.gca(projection=m)
----> 3 c.plot(**m.plot_settings,axes=ax)

~/anaconda/envs/sunkit-dem/lib/python3.7/site-packages/ndcube/mixins/plotting.py in plot(self, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
     81                 if naxis == 2:
     82                     ax = self._plot_2D_cube(axes, plot_axis_indices, axes_coordinates,
---> 83                                             axes_units, data_unit, **kwargs)
     84                 else:
     85                     ax = self._plot_3D_cube(

~/anaconda/envs/sunkit-dem/lib/python3.7/site-packages/ndcube/mixins/plotting.py in _plot_2D_cube(self, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
    263                 ax.set_xlabel(xlabel)
    264                 ax.set_ylabel(ylabel)
--> 265         return ax
    266 
    267     def _plot_3D_cube(self, plot_axis_indices=None, axes_coordinates=None,

UnboundLocalError: local variable 'ax' referenced before assignment

Steps to Reproduce

import sunpy.data.sample
import ndcube
import matplotlib.pyplot as plt
m = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
c = ndcube.NDCube(m.data,m.wcs)
fig = plt.figure()
ax = fig.gca(projection=m)
c.plot(**m.plot_settings,axes=ax)

System Details

  • ndcube Version: 1.1.3
  • SunPy Version: 1.0.2
  • Python Version: 3.7.3
  • OS information: macOS 10.14.5 (Mojave)
@DanRyanIrish
Copy link
Member

Thanks @wtbarnes. Can you by any chance revert to ndcube 1.1.2 and confirm the same behaviour is produced?

@wtbarnes
Copy link
Member Author

wtbarnes commented Aug 8, 2019

Yep, this error pops up in v1.1.2 as well

@DanRyanIrish
Copy link
Member

OK, thanks. We'll add it to the next milestone.

@DanRyanIrish DanRyanIrish added this to the 1.2 milestone Aug 8, 2019
@Cadair Cadair self-assigned this Sep 4, 2019
Cadair added a commit to Cadair/ndcube that referenced this issue Sep 10, 2019
Cadair added a commit to Cadair/ndcube that referenced this issue Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants