Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does my colorbar have lines in it?

Edit: Since this seems to be a popular post, here's the solution that seems to be working well for me. Thanks @gazzar and @mfra.

cbar.solids.set_rasterized(True) cbar.solids.set_edgecolor("face") 

Does anyone know why my colorbar has what appear to be lines in it? Or rather why is the color transition not smooth? I'm using basemap, obviously, but that shouldn't matter since it's all matplotlib calls under the hood AFAICT. I create the map doing something like

grays = plt.cm.get_cmap("Grays") sc = mymap.scatter(xpoints, ypoints, s=sizes, c=color_values, cmap=grays, alpha=.75,                    marker="o", zorder=10, vmin=0, vmax=1) cbar = mymap.colorbar(sc, drawedges=True, location="bottom") 

I tried without and without alpha and the result was the same. Maybe it is because my color_values array is not fine enough? Can I set the underlying values that are mapped to the colorbar somewhere? I don't see how, and I don't see this problem elsewhere. Ie., I can replicate the matplotlib show_colorbars example without this problem.

Bad Colorbar Example

like image 913
jseabold Avatar asked Feb 21 '13 13:02

jseabold


2 Answers

In case you create vector graphics, have you tried this (taken from http://matplotlib.org/api/pyplot_api.html?highlight=colorbar#matplotlib.pyplot.colorbar):

"It is known that some vector graphics viewer (svg and pdf) renders white gaps between segments of the colorbar. This is due to bugs in the viewers not matplotlib. As a workaround the colorbar can be rendered with overlapping segments:

cbar = colorbar() cbar.solids.set_edgecolor("face") draw() 

However this has negative consequences in other circumstances. Particularly with semi transparent images (alpha < 1) and colorbar extensions and is not enabled by default see (issue #1188)."

like image 161
mfra Avatar answered Oct 11 '22 13:10

mfra


It looks like your plot uses some transparent (alpha) values. I was having this same problem (semi-transparent plot, but wanted the color bar to be solid), and this question and answer fixed it for me! For reference:

cbar.set_alpha(1) cbar.draw_all() 
like image 27
Wesley Baugh Avatar answered Oct 11 '22 15:10

Wesley Baugh