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

"NameError: name 'subplots' is not defined"bug in 'all_angles.py' #103

Open
Flemyng1999 opened this issue May 8, 2023 · 1 comment
Open

Comments

@Flemyng1999
Copy link

Flemyng1999 commented May 8, 2023

When I run code-1 (copied from https://py6s.readthedocs.io/en/latest/helpers.html#running-for-many-angles):

from Py6S import *

s = SixS()
s.ground_reflectance = GroundReflectance.HomogeneousRoujean(0.037, 0.0, 0.133)
s.geometry.solar_z = 30
s.geometry.solar_a = 0
SixSHelpers.Angles.run_and_plot_360(s, 'view', 'pixel_reflectance')

Output this:

  File "C:\Users\xxx\miniconda3\envs\py6s-env\lib\site-packages\Py6S\SixSHelpers\all_angles.py", line 234, in plot_polar_contour
    fig, ax = subplots(subplot_kw=dict(projection="polar"), figsize=figsize)
NameError: name 'subplots' is not defined

So I make a change in 'all_angles.py':

    @classmethod
    def plot_polar_contour(
        cls, values, azimuths, zeniths, filled=True, colorbarlabel="", figsize=None
    ):
        # I added
        try:
            from matplotlib.pyplot import subplots
        except ImportError:
            raise ImportError("You must install matplotlib to use the plotting functionality")
            
        theta = np.radians(azimuths)
        zeniths = np.array(zeniths)

        values = np.array(values)
        values = values.reshape(len(azimuths), len(zeniths))

        r, theta = np.meshgrid(zeniths, np.radians(azimuths))
        fig, ax = subplots(subplot_kw=dict(projection="polar"), figsize=figsize)
        ax.set_theta_zero_location("N")
        ax.set_theta_direction(-1)
        if filled:
            cax = ax.contourf(theta, r, values, 30)
        else:
            cax = ax.contour(theta, r, values, 30)
        cb = fig.colorbar(cax)
        cb.set_label(colorbarlabel)

        return fig, ax, cax

The code-1 can run

@machenme
Copy link

does not work for jupyter . but original file can work with py file.

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

2 participants