Skip to content
Advertisement

Proplot colorbar from custom cmap

I’d like to add a colorbar to my figure from a Colormap object rather than using a mappable (such as returned from imshow.

From the docs I think this should be possible using option 4.

I’m using the following code:

JavaScript

This gives the following result:

cbar_1

Which almost what I want but I’d like to color bar values to ranges from -100 to 100, which I thought the values parameter would do. If I look at the code it seems that values are ignored in favor of np.linspace(0, 1)

I’ve tried this:

JavaScript

This more or less works but I’d prefer to just hand the cmap to proplot and let it work its magic.

Using a ScalarMappable as per this post doesn’t work with proplot:

JavaScript

Advertisement

Answer

EDIT: A better way is to pass the Normalize to colorbar as well. This also allows using locator:

JavaScript

enter image description here

Original answer by settings the ticks and then overriding the labels:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement