Skip to content

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

@Flemyng1999

Description

@Flemyng1999

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions