views:

747

answers:

2

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?

I greatly appreciate all your thoughts!!!

A mountain-dew and fiery-hot cheetos to all! -Allen

+4  A: 

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

tom10
Hi Tom! Yes! This is exactly the type of thing I wanted. You did use sub-plots, however, instead of two separate images, which may be my downfall. I was about to try subplots with a very large 6-up plotting page as an example (which did follow this rule). I'm wondering if the vmin/vmax is broken in separate pictures? I'll use your example and test it out this evening or tomorrow and come back with my results! I will have a checkmark for you when I return most likely! :) Thank you for posting a reply!! See you within 24 hours here. Cheers!!!! (extra mountain-dew for you, sir!)
AllenH
just ran through the example- love it- explained a few things to me at the same time. Interesting to see that the subplot is associated with all plt.*'s below it. I've been using handles for it. I will alter the example for individual plots now. :)
AllenH
Ok! Using the simple example above, and simply plotting each figure separately (how I was working with my dataset), the color was kept! very glad it was too! LOL. So, maybe it's my use of errorbar underneath my scatter command... but, I will investigate. You have proven to me it works! :) Thanks, Tom!
AllenH
Well, in my current implementation, it doesn't work! LOL I'm adding an answer with my post below with the non-working code, and will add another answer when I get it working. If you hadn't posted, Tom, I wouldn't have thought it was working, so thank you for doing so!
AllenH
A: 
AllenH
This is because your color values are different in each plot (i.e. CurrentsArray and rf85CurrentsArray have different values at the same x and y coordinate). For example, the small dot up around 1.0 on the y-axis has the color value 0.47368421 in the first plot and 0.92515847 in the second. You can see this is you write the value next to each spot using plt.text(x, y, val).
tom10
By the way, I think it would have been better to ask this as a separate question rather than post this second question as an answer. Here I need to answer in a comment which has all sorts of limitations – no code, no figures, no formatting, etc, etc. That is, your first question was "how to use the same color scale", your second question is more of a "what's wrong with my code".
tom10
Ah! Thanks for the pointer, Tom! I'm new to stackoverflow, so I'm slowly figuring my way around. :). I appreciate it! I'll definitely look at the values carefully! They shouldn't be different! Problem with my work to produce them if so!! Thank you!
AllenH
Maybe you've just got something small mixed up. Here, rf85CuSearray and rf85CurrentsArray are exactly the same, which seems odd.
tom10
Tom- you're absolutely correct- I often reuse snippets of code in matlab since they're available easily in the up-arrow buffer- and I think I missed changing something!! You've hit the nail on the head here. Thank you for all your comments- I've learned a lot from you!! I love the little plt.text trick! :)My hat is off to you, Tom! Thank you for your time spent on this!
AllenH