Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing color in scatter plots in matplotlib

I want to fix the color range on multiple scatter plots and add in a colorbar to each plot (which will be the same in each figure). Essentially, I'm fixing all aspects of the axes and colorspace etc. so that the plots are directly comparable by eye.

For the life of me, I can't seem to figure out all the various ways of fixing the color-range. I've tried vmin, vmax, but it doesn't seem to do anything, I've also tried clim(x,y) and that doesn't seem to work either.

This must come up here and there, I can't be the only one that wants to compare various subsets of data amongst plots... so, how do you fix the colors so that each data keeps it's color between plots and doesn't get remapped to a different color due to the change in max/min of the subset -v- the whole set?

like image 250
AllenH Avatar asked May 27 '10 23:05

AllenH


People also ask

How do you set the color on a scatter?

scatter( x , y , sz , c ) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as 'red' .

How do I change the marker color in matplotlib?

All of the line properties can be controlled by keyword arguments. For example, you can set the color, marker, linestyle, and markercolor with: plot(x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12).


1 Answers

Setting vmin and vmax should do this.

Here's an example:

import matplotlib.pyplot as plt  xyc = range(20)  plt.subplot(121) plt.scatter(xyc[:13], xyc[:13], c=xyc[:13], s=35, vmin=0, vmax=20) plt.colorbar() plt.xlim(0, 20) plt.ylim(0, 20)  plt.subplot(122) plt.scatter(xyc[8:20], xyc[8:20], c=xyc[8:20], s=35, vmin=0, vmax=20)    plt.colorbar() plt.xlim(0, 20) plt.ylim(0, 20)  plt.show() 

And the plot this produces:

alt text

like image 195
tom10 Avatar answered Oct 03 '22 03:10

tom10