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

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

Closed
HealthyPear opened this issue Jun 29, 2023 · 5 comments
Closed

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

HealthyPear opened this issue Jun 29, 2023 · 5 comments

Comments

@HealthyPear
Copy link

HealthyPear commented Jun 29, 2023

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 HealthyPear changed the title plot_sky crashes with matplotlib>3.4.0 plot_sky crashes with matplotlib>v3.4.0 and astroplan v0.8 Jun 29, 2023
@HealthyPear
Copy link
Author

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
Copy link
Contributor

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

@wtgee
Copy link
Contributor

wtgee commented Jun 30, 2023 via email

@HealthyPear
Copy link
Author

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
Copy link
Author

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

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

No branches or pull requests

3 participants