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

Usage of non-uniform levels in contourf not getting clipped? #1723

Open
lsawade opened this issue Feb 2, 2021 · 1 comment
Open

Usage of non-uniform levels in contourf not getting clipped? #1723

lsawade opened this issue Feb 2, 2021 · 1 comment

Comments

@lsawade
Copy link

lsawade commented Feb 2, 2021

Description

There seems to be a bug in contourf or maybe this is expected behavior. Nonuniform levels seem to "undo" masking or nan masked arrays.

example

Code to reproduce

data: data.npz.zip

import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import cartopy
from cartopy.crs import PlateCarree, Mollweide
import numpy as np

data = np.load("data.npz")
lat = data['lat']
lon = data['lon']
depth = data['depth']

# Get cmap
colormap = plt.get_cmap('jet')

# Create colormap and define uniform levels
levels_unif = np.arange(0.0, 700.0, 50.0)
colors = colormap(np.linspace(0, 1, len(levels_unif)))
cmap = ListedColormap(colors)

# Create colormap and define non uniform levels
levels_nonunif = np.array([0.0, 10.0, 15.0, 25.0, 75.0, 100.0, 150.0, 200.0,
                          300.0, 400.0, 600.0])
colors = colormap(np.linspace(0, 1, len(levels_nonunif)))
cmap = ListedColormap(colors)

plt.figure(figsize=(10, 5))
ax = plt.subplot(121, projection=Mollweide(central_longitude=-150.0))
ax.add_feature(cartopy.feature.LAND, edgecolor='black',
               linewidth=0.5, facecolor=(0.9, 0.9, 0.9))
plt.contourf(lon, lat, depth, levels=levels_unif,
             transform=PlateCarree(central_longitude=0.0),
             cmap=cmap)
plt.colorbar(orientation='horizontal', aspect=50)

ax2 = plt.subplot(122, projection=Mollweide(central_longitude=-150.0))
ax2.add_feature(cartopy.feature.LAND, edgecolor='black',
               linewidth=0.5, facecolor=(0.9, 0.9, 0.9))
plt.contourf(lon, lat, depth, levels=levels_nonunif,
             transform=PlateCarree(central_longitude=0.0),
             cmap=cmap)
plt.colorbar(orientation='horizontal', aspect=50)

@greglucas
Copy link
Contributor

I think this is due to one of the non-uniform levels not getting clipped/wrapped properly and filling the entire domain. Likely similar to issue #1076?

@lsawade lsawade changed the title Usage of non-uniform levels in contourf cancel masking? Usage of non-uniform levels in contourf not getting clipped? Feb 5, 2021
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

3 participants