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 levels issue with small range values #124

Closed
mickaellalande opened this issue Feb 24, 2020 · 3 comments
Closed

Colorbar levels issue with small range values #124

mickaellalande opened this issue Feb 24, 2020 · 3 comments

Comments

@mickaellalande
Copy link
Contributor

I'm having trouble with colorbar recently, here is an example of it (link with #117? ; I didn't update recently I hope this haven't been solved already, proplot version: 0.4.2):

A first example that works (I purposely multiplied the temperature by 0.01 for having small values for next examples):

import xarray as xr
import proplot as plot

da = xr.tutorial.open_dataset('air_temperature').isel(time=0).air

f, axs = plot.subplots(proj='cyl', axwidth=3)

cmap='ColdHot'
levels=plot.arange(-10,10, 1)

m = axs.pcolormesh(((da-273.15)*0.01), cmap=cmap, levels=levels, colorbar='r')

axs.format(labels=True, coast=True, borders=True,
    latlim=(da.lat.min(), da.lat.max()), lonlim=(da.lon.min(), da.lon.max())
)

temp_1

Then with

levels=plot.arange(-2, 2, 0.1)

temp_2

It still works but already the 0 is not good...

And if I go for a smaller range:

levels=plot.arange(-1, 1, 0.1)

this time I have an error:

[...]
~/miniconda3/lib/python3.7/site-packages/proplot/axistools.py in __call__(self, x, pos)
    468                 # Hard limit of MAX_DIGITS sigfigs
    469                 string = ('{:.%df}' % min(
--> 470                     abs(np.log10(x) // 1), MAX_DIGITS)).format(x)
    471                 continue
    472             break

ValueError: cannot convert float NaN to integer

Knowing that it is the levels I need to use for another application, so I'm stuck for now.

@lukelbd
Copy link
Collaborator

lukelbd commented Feb 24, 2020

This can be temporarily fixed by applying a SimpleFormatter with explicitly limited decimal precision (see #117), e.g. as follows:

ax.colorbar(..., formatter='simple')

Note that by default, this formatter still trims trailing zeros (this can also be turned off with the zerotrim argument).

I'm pretty busy this week but will try to fix this by next weekend; this issue has high priority. Thanks for the report.

@mickaellalande
Copy link
Contributor Author

ax.colorbar(..., formatter=('simple', 3))

Ok, great thanks for the trick! It works fine so far like this 😄

@lukelbd
Copy link
Collaborator

lukelbd commented May 9, 2020

This issue should be fixed for >=99% of cases by 9b7f89f, specifically the lines:

https://github.com/lukelbd/proplot/blob/9b7f89fdad3a8e127570aeccbe138c9c089d1fff/proplot/ticker.py#L467-L491

@lukelbd lukelbd closed this as completed May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants