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

Norm keywords aren't passing properly to colormap #29

Closed
bradyrx opened this issue Sep 2, 2019 · 3 comments
Closed

Norm keywords aren't passing properly to colormap #29

bradyrx opened this issue Sep 2, 2019 · 3 comments
Labels

Comments

@bradyrx
Copy link
Collaborator

bradyrx commented Sep 2, 2019

I'm finding that the keywords for e.g. LogNorm are not passing through the wrapper to matplotlib appropriately. Using the same data as when we discussed the LogNorm colorbar in #25: http://s000.tinyupload.com/index.php?file_id=02946064711977690771.

Below, see that proplot can't modify the LogNorm boundaries.

With proplot:

f, ax = plot.subplots(proj='pcarree', tight=False, axwidth=6,)

p = ax.contourf(chl.lon, chl.lat, chl.values, norm='log', norm_kw={'vmin': 0.01, 'vmax': 10}, levels=30,
                cmap='Fire', )

ax.format(latlim=(20, 50), lonlim=(-140, -105), land=True)
ax.colorbar(p, loc='r')

Screen Shot 2019-09-02 at 10 36 55 AM

With matplotlib:

f, ax = plt.subplots()
p = plt.pcolormesh(chl.lon, chl.lat, chl.values, norm=colors.LogNorm(vmin=0.01, vmax=1), cmap='Fire')
plt.colorbar(p)

Screen Shot 2019-09-02 at 10 38 24 AM

@lukelbd
Copy link
Collaborator

lukelbd commented Sep 2, 2019

If you pass vmin and vmax to contourf directly, they will be used:

ax.contourf(chl.lon, chl.lat, chl.values, norm='log', vmin=0.01, vmax=10, levels=30, cmap='Fire', ) 

But it's definitely not right to just ignore norm_kw. Just pushed a patch (5b09d89), now cmap_wrapper checks to see if vmin and vmax were passed in the norm_kw dictionary.

@lukelbd lukelbd closed this as completed Sep 2, 2019
@bradyrx
Copy link
Collaborator Author

bradyrx commented Sep 2, 2019

@lukelbd, FYI, this solution doesn't work. I forgot I tried that before.

plot.rc['geogrid.alpha'] = 0

plot.rc.fontname = 'Helvetica Light'
f, ax = plot.subplots(proj='cyl', axwidth='8cm',)
p = ax.contourf(chl.lon, chl.lat, chl, norm='log', vmin=0.01, vmax=10, levels=30)
ax.colorbar(p, loc='r')
ax.format(land=True, latlim=(20, 50), lonlim=((-140, -105)))

Screen Shot 2019-09-02 at 4 06 12 PM

I think you might get this behavior if you use the LogLocator directly. (https://matplotlib.org/3.1.1/gallery/images_contours_and_fields/contourf_log.html)

@lukelbd
Copy link
Collaborator

lukelbd commented Sep 2, 2019

Okay this patch seems to do the trick: a3ebbb1. Try:

f, ax = plot.subplots()
ax.pcolormesh(10**(np.random.rand(10,10)*5), vmin=0.1, vmax=10, norm='log', colorbar='r')

Previously if you specified both vmin and vmax I just set the levels to np.linspace(vmin, vmax, N), because most locators treat vmin and vmax as suggested locations, not absolute locations. For example, if you used vmax=20, the actual level maximum would be 10. But now this is documented, and I think it makes more sense that if you really want exact locations, you should provide your own levels array.

@lukelbd lukelbd added the bug label Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants