Skip to content

UnboundLocalError: local variable 'fig' referenced before assignment #122

@xushanthu-2014

Description

@xushanthu-2014

The error happens when I ran the code:

    import matplotlib.pyplot as plt
    fig = plt.figure(figsize=(25, 7))
    ax1 = fig.add_subplot(111, projection='polar')
    ax2 = fig.add_subplot(121, projection='polar')
    
    # plot BRDF and phase function
    plot1 = SRF.polarplot(inc = list(np.linspace(0,85,5)), multip = 1.5, legpos = (0.,0.5), polarax=ax2,
                         label='Surface scattering phase function', legend=True)
    plot2 = V.polarplot(inc = list(np.linspace(0,120,5)) ,multip = 1.5, legpos = (0.0,0.5), polarax=ax1,
                         label='Volume scattering phase function', legend=True)
    
    fig.tight_layout()

in the example: https://github.com/TUW-GEO/rt1/blob/master/doc/examples/example_lin_comb.ipynb.
The error information is:

Traceback (most recent call last):

  File "/Users/xushan/opt/anaconda3/envs/py310/lib/python3.10/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "/Users/xushan/research/TUD/vodca/demo_rt1.py", line 120, in <module>
    plot1 = SRF.polarplot(inc = list(np.linspace(0,85,5)), multip = 1.5, legpos = (0.,0.5), polarax=ax1,

  File "/Users/xushan/opt/anaconda3/envs/py310/lib/python3.10/site-packages/rt1/rtplots.py", line 263, in polarplot
    return fig

UnboundLocalError: local variable 'fig' referenced before assignment

It seems that the fig is not explicitly assigned in the function rtplots.py if polarax is not None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions