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

colorbar_position not working in 3.2.0 #8

Closed
alaniwi opened this issue Mar 20, 2023 · 1 comment
Closed

colorbar_position not working in 3.2.0 #8

alaniwi opened this issue Mar 20, 2023 · 1 comment

Comments

@alaniwi
Copy link

alaniwi commented Mar 20, 2023

colorbar_position is broken (for some use cases at least) in 3.2.0

Test case:

data file test.nc attached (<1MB, but in a zip file because GitHub doesn't allow attaching .nc directly): test.nc.zip

Broken example (paths redacted in error message):

>>> import cf
>>> cf.__version__
'3.14.1'
>>> import cfplot as cfp
>>> cfp.__version__
'3.2.0'
>>> f=cf.read('test.nc')[1]
>>> f
<CF Field: eastward_wind(time(1), pressure(1), latitude(160), longitude(320)) m s**-1>
>>> cfp.con(f, colorbar_position=[0.1, 0.1, 0.8, 0.02])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/cfplot/cfplot.py", line 1029, in con
    cbar(labels=cbar_labels, orientation=cb_orient, position=colorbar_position,
  File "/path/to/cfplot/cfplot.py", line 8256, in cbar
    colorbar = matplotlib.colorbar.ColorbarBase(ax1, cmap=cmap,
UnboundLocalError: local variable 'ax1' referenced before assignment

Working example (same code, earlier cfplot version - also a different cf version but guessing that this is unimportant):

>>> import cf
>>> cf.__version__
'3.13.0'
>>> import cfplot as cfp
>>> cfp.__version__
'3.1.23'
>>> f=cf.read('test.nc')[1]
>>> f
<CF Field: eastward_wind(time(1), pressure(1), latitude(160), longitude(320)) m s**-1>
>>> cfp.con(f, colorbar_position=[0.1, 0.1, 0.8, 0.02])
>>> 

produces:
image

@ajheaps
Copy link
Collaborator

ajheaps commented Mar 31, 2023

Thanks for the bug report. I had rewritten the cf-plot cbar routine somewhat and had a indent too far for the code related to the position option. This is fixed in cf-plot 3.2.7

@ajheaps ajheaps closed this as completed Mar 31, 2023
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