Displaying colorbars with specified boundaries correctly

Currently, colorbar takes boundaries and values kwargs. If values is specified, len(values) must be len(boundaries)-1. values can be None. For either case the colorbar displays one color between 2 boundaries. This means colorbars for complex colormaps can be displayed incorrectly.

I’m working on what will eventually become a pull request:

(For more on inconsistent plotting of the red line, see the next post.)

If boundaries is specified and values is not, I uniformly space 1000 values between each set of boundaries to retrieve colors. 1000 is an arbitrary choice—can I make it less arbitrary?

Re: the red line: whether or not it shows up in the colorbar depends on the backend. The above image is from PNG output; here is a screenshot of PDF output:

What’s going on?

Can you post the code you are using? Not particularly following what you are trying to do, and what might be going wrong…

You’ll need to grab colorbar.py from my fork:

https://github.com/kdpenner/matplotlib/blob/colorbar-boundaries/lib/matplotlib/colorbar.py

And then run this code:

to generate the PNG. Change the last line to get a PDF version.

So, are you just letting us know you are working on this or are you asking for something?

As I mentioned, 2 questions:

  1. If boundaries is specified and values is not, I uniformly space 1000 values between each set of boundaries to retrieve colors. 1000 is an arbitrary choice—can I make it less arbitrary?

  2. Re: the red line: whether or not it shows up in the colorbar depends on the backend. What’s going on?

Consistent plotting of the red line requires higher dpi than the default.