astropy / astroplan

Observation planning package for astronomers – maintainer @bmorris3
https://astroplan.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
198 stars 109 forks source link

plot_sky crashes with matplotlib>v3.4.0 and astroplan v0.8 #561

Closed HealthyPear closed 9 months ago

HealthyPear commented 1 year ago

Calling plot_sky from astroplan v0.8 with matplotlib > 3.4 triggers a TypeError

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [147], line 1
----> 1 plot_sky(FixedTarget(coord=source_altaz, name=source_name), Observer.at_site('Roque de los Muchachos'), time, north_to_east_ccw=False)
      3 plt.legend(loc='center left', bbox_to_anchor=(1.25, 0.5))
      4 plt.show()

File ~/Applications/mambaforge/envs/astro/lib/python3.10/site-packages/astropy/units/decorators.py:316, in QuantityInput.__call__.<locals>.wrapper(*func_args, **func_kwargs)
    314 # Call the original function with any equivalencies in force.
    315 with add_enabled_equivalencies(self.equivalencies):
--> 316     return_ = wrapped_function(*func_args, **func_kwargs)
    318 # Return
    319 ra = wrapped_signature.return_annotation

File ~/Applications/mambaforge/envs/astro/lib/python3.10/site-packages/astroplan/plots/sky.py:120, in plot_sky(target, observer, time, ax, style_kwargs, north_to_east_ccw, grid, az_label_offset, warn_below_horizon, style_sheet)
    118 # Set up axes & plot styles if needed.
    119 if ax is None:
--> 120     ax = plt.gca(projection='polar')
    121 if style_kwargs is None:
    122     style_kwargs = {}

TypeError: gca() got an unexpected keyword argument 'projection'

caused by the deprecation and later removal of the keywords associated to plt.cga()

see https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.4.0.html#pyplot-gca-and-figure-gca-keyword-arguments

The deprecation notice using matplotlib v3.4 read in fact as follows,

Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments.
The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().

So solution to this problem is to:

  1. require a matpltlib version way more recent than the one you are currently using as the bottom limit in your setup.cfg (v1.4)
  2. modifying the plot_sky function to do ax = fig.add_subplot(projection='polar') instead of ax = plt.gca(projection='polar')
HealthyPear commented 1 year ago

I noticed that this doesn't happen and the function behaves as expected if I use the development version.

I guess you either fixed this bug or modified the code for other reasons and you fixed it without realizing it was there.

What about a bugfix release v0.8.1?

bmorris3 commented 1 year ago

Hi @HealthyPear, thanks for the heads up. I think we're probably due for v0.9 anyways. @wtgee – any objections?

wtgee commented 1 year ago

On Thu, Jun 29, 2023 at 04:21 Brett M. Morris @.***> wrote:

Hi @HealthyPear https://github.com/HealthyPear, thanks for the heads up. I think we're probably due for v0.9 anyways. @wtgee https://github.com/wtgee – any objections?

No objections here! It would be nice to get #555 in before a release, which I could try to work on this weekend.

Reply to this email directly, view it on GitHub https://github.com/astropy/astroplan/issues/561#issuecomment-1613270149, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAARIUF62KCCUQ2B5A42FQLXNWFOZANCNFSM6AAAAAAZYJCBSY . You are receiving this because you were mentioned.Message ID: @.***>

-- ~Wilfred Tyler Gee

HealthyPear commented 11 months ago

I stumbled upon this issue again, so since months have passed if I were you I'd just go for a bugfix release (0.8.1)

HealthyPear commented 9 months ago

With matplotlib 3.8.1 and astoplan 0.9.1 this bug is solved - closing.