Skip to content

LogNorm colormap doesn't work correctly #25

@bradyrx

Description

@bradyrx

Using the LogNorm colormap argument in, e.g., pcolormesh doesn't work correctly in proplot.

Data link: http://s000.tinyupload.com/index.php?file_id=02946064711977690771

With matplotlib:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import matplotlib.colors as colors

ds = xr.open_dataset('chl_cal.nc')

f, ax = plt.subplots(subplot_kw=dict(projection=ccrs.PlateCarree()))
p = ax.pcolormesh(ds.lon, ds.lat, ds, norm=colors.LogNorm(vmin=ds.min(), vmax=ds.max()))
plt.colorbar(p)

Screen Shot 2019-07-09 at 4 50 54 PM

With proplot:

f, ax = plot.subplots(proj='pcarree', tight=False, axwidth=6, colorbar='r')
p = ax.pcolormesh(ds.lon, ds.lat, ds.values, norm=colors.LogNorm(vmin=ds.min(), vmax=ds.max()))
ax.set_extent([-140, -105, 20, 50])
f.rightpanel.colorbar(p)

Screen Shot 2019-07-09 at 4 51 28 PM

Here's a workaround, but I think using LogNorm is preferred so it handles the labeling and all that for you. Now this is of course in actual log10 units.

# Just log-transform before
ds = np.log10(ds)
f, ax = plot.subplots(proj='pcarree', tight=False, axwidth=6, colorbar='r')
p = ax.pcolormesh(ds.lon, ds.lat, ds.values,)
ax.set_extent([-140, -105, 20, 50])
f.rightpanel.colorbar(p)

Screen Shot 2019-07-09 at 4 52 33 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions