[Matplotlib-users] plot 2 figures with same color scales

Bruno Pagani bruno.pagani at astrophysics.eu
Thu Mar 28 12:00:05 EDT 2019


Maybe I missed something, but wouldn’t just fixing vmin and vmax in the scatter do the job?

Regards,
Bruno

Le 28 mars 2019 16:56:32 GMT+01:00, Neal Becker <ndbecker2 at gmail.com> a écrit :
>I'm trying to make 2 scatter plots where the colors of each point 
>corresponds to the value of a 1d array.
>
>I want to do this so that the colors used in the 2 plots are
>comparable.  
>That is, in plot 1 a violet dot means the same value as on plot 2.
>
>I tried the following code.  Here values2 is clearly different than
>values1.  
>But it appears that the plots are colored with the same colors.  And
>the 
>colorbar scales are different.  What I want is to have the colorbar
>scales 
>be the same, and the colors on the plot are different.
>
>So for example, if point #1 on plot 1 has a value of 0.4, and point #1
>on 
>plot 2 has a value of 0.5, the colors used to represent given values on
>the 
>2 plots are the same.  I believe that without colorbar, just using
>scatter 
>with specific c=value, I do get this result.  But adding colorbar I
>think 
>changes all the colors.
>
>Any suggestions?
>
>
>import numpy as np
>pts = np.random.uniform (0, 1, 100) + 1j*np.random.uniform(0, 1, 100)
>values1 = np.random.uniform(0, 1, 100)
>#values2 = np.random.uniform(0.2, 1, 100)
>values2 = values1 * 0.8 + 0.2
>
>import matplotlib.pyplot as plt
>for value in (values1, values2):
>    fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
>    cmap=plt.get_cmap('plasma')
>    blah = ax.scatter (pts.real, pts.imag, c=value, s=10)
>    blah.set_array (value)
>    fig.colorbar (blah)
>plt.show()
>
>
>_______________________________________________
>Matplotlib-users mailing list
>Matplotlib-users at python.org
>https://mail.python.org/mailman/listinfo/matplotlib-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190328/b83b57af/attachment.html>


More information about the Matplotlib-users mailing list