distinct colors in colorbar for linecollection

Dear all!

I’m folowing the line_collection2.py example to create a LineCollection plot with a colorbar.
How can I force the colorbar to show distinct lines like it does in contour plots for a LineCollection plot?

Thanks! Bernhard

Bernhard,

Are you sure you want a colorbar with lines and not a legend?

A colorbar with lines only, matching a LineCollection, can be done with the facilities in mpl's colorbar.py module; you might take a look at the code in that module to see how it is being done in the line contour case. Note that ColorbarBase has a method, add_lines, for this. I'm sorry I don't have time to be more specific now, though.

Eric

Bernhard Voigt wrote:

···

Dear all!

I'm folowing the line_collection2.py example to create a LineCollection plot with a colorbar.
How can I force the colorbar to show distinct lines like it does in contour plots for a LineCollection plot?

Thanks! Bernhard

Hi Eric!

Are you sure you want a colorbar with lines and not a legend?

Well, I’ve got a couple of lines (~50) and thus the legend would become confusing.
I wanted to have lines in the colorbar because I think it’s more adequate to have lines in the bar when there are lines in the plot.

A colorbar with lines only, matching a LineCollection, can be done with

the facilities in mpl’s colorbar.py module; you might take a look at

the code in that module to see how it is being done in the line contour

case. Note that ColorbarBase has a method, add_lines, for this. I’m

sorry I don’t have time to be more specific now, though.

Thanks for the hint! I was quite simple, I made a call to pylab.colorbar(filled=False) which gave me an empty colorbar. Then I add lines to this instance:

colorbar.ColorbarBase.add_lines(cbar, myrange, linecl.get_colors(), linecl.get_linewidth())

Thanks! Bernhard

···

Eric

Bernhard Voigt wrote:

Dear all!

I’m folowing the line_collection2.py example to create a LineCollection

plot with a colorbar.

How can I force the colorbar to show distinct lines like it does in

contour plots for a LineCollection plot?

Thanks! Bernhard