Skip to content

Conversation

lukelbd
Copy link
Collaborator

@lukelbd lukelbd commented Feb 5, 2020

This PR will permit descending colorbar levels. This is not restoring a native matplotlib feature; it is a new proplot feature. I'm adding this simply because I wanted it for one of my plots, and there's no good reason proplot/matplotlib should have this limitation.

The following example demonstrates how this works for both evenly spaced and unevenly spaced levels:

import proplot as plot
import numpy as np
data = np.random.rand(20, 20).cumsum(axis=0)
for levels in (
    np.arange(0, 15, 1)[::-1],  # with Normalizer
    [15, 10, 5, 2, 1, 0],  # with LinearSegmentedNorm
):
    f, ax = plot.subplots()
    ax.pcolormesh(data, levels=levels, colorbar='b')

image
image

@lukelbd lukelbd added the feature label Feb 5, 2020
@lukelbd
Copy link
Collaborator Author

lukelbd commented Feb 5, 2020

Here's an example showing this works with parametric plots too:

import proplot as plot
values = np.linspace(0, 9, 10)[::-1]  # with Normalizer
f, ax = plot.subplots()
x = y = np.arange(10)
ax.parametric(x, y, lw=5, cmap='Fire', values=values, colorbar='b')

image

@lukelbd lukelbd merged commit 8af372d into master Feb 5, 2020
@lukelbd lukelbd deleted the descending-cbar-levs branch February 5, 2020 21:57
@lukelbd
Copy link
Collaborator Author

lukelbd commented Feb 5, 2020

Please note that due to limitations of matplotlib's contouring algorithm (matplotlib/matplotlib#5477), this will not work for contour plots. I guess this used to be a bug when that discussion was going on, but now matplotlib explicitly enforces increasing contour levels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant