# plot 2 figures with same color scales Classic List Threaded 4 messages Reply | Threaded
Open this post in threaded view
|

## plot 2 figures with same color scales

 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 [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

## Re: plot 2 figures with same color scales

 This is a similar problem to that of plotting two imshow()'s. You should be able to pass vmin/vmax arguments to scatter, I believe.BenOn Thu, Mar 28, 2019 at 11:57 AM Neal Becker <[hidden email]> wrote: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 [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users _______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

## Re: plot 2 figures with same color scales

 In reply to this post by Neal Becker Maybe I missed something, but wouldn’t just fixing vmin and vmax in the scatter do the job?Regards,BrunoLe 28 mars 2019 16:56:32 GMT+01:00, Neal Becker <[hidden email]> 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 nppts = 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.2import matplotlib.pyplot as pltfor 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[hidden email]https://mail.python.org/mailman/listinfo/matplotlib-users`_______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

## Re: plot 2 figures with same color scales

 In reply to this post by Neal Becker Hey Neal,I modified your example a bit, is that what you want?import numpy as npimport matplotlib.pyplot as pltpts = np.random.uniform(0, 1, 100) + 1j * np.random.uniform(0, 1, 100)values1 = np.random.uniform(0, 1, 100)values2 = values1 * 0.1 + 0.2global_max = np.max([values1.max(), values2.max()])global_min = np.min([values1.min(), values2.min()])fig, axes = plt.subplots(ncols=2)for ax, value in zip(axes, [values1, values2]):    blah = ax.scatter(pts.real, pts.imag, c=value, s=10,                      vmin=global_min, vmax=global_max)    cbar = fig.colorbar(blah, ax=ax)    fig.tight_layout()On Thu, Mar 28, 2019 at 8:57 AM Neal Becker <[hidden email]> wrote: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 [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users _______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users