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

another get_cmap fix #564

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions pyleoclim/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,24 +1395,6 @@ def keep_center_colormap(cmap, vmin, vmax, center=0):
the centered value across the data. This adjusted colormap can then be used for data visualization tasks
where maintaining a perceptual 'zero' or central reference point is important.
Examples
--------
.. jupyter-execute::
import matplotlib.pyplot as plt
import pyleoclim as pyleo
new_colormap = pyleo.utils.plotting.keep_center_colormap('RdBu', vmin=-300, vmax=300, center=0)
plt.imshow(data, cmap=new_colormap)
plt.colorbar()
This will create and use a colormap where the value 0 is centered, and the colormap is adjusted
to symmetrically represent deviations from this center, making it suitable for displaying anomalies
or differences from a baseline in a visually balanced manner.
"""

vmin = vmin - center
Expand All @@ -1424,7 +1406,7 @@ def keep_center_colormap(cmap, vmin, vmax, center=0):

dv = max(-vmin, vmax) * 2
N = int(256 * dv / (vmax - vmin))
cont_map = cm.get_cmap(cmap, N)
cont_map = plt.get_cmap(cmap, N)
newcolors = cont_map(np.linspace(0, 1, N))
beg = int((dv / 2 + vmin) * N / dv)
end = N - int((dv / 2 - vmax) * N / dv)
Expand Down
Loading