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

Benjamin Root ben.v.root at gmail.com
Thu Mar 28 11:59:46 EDT 2019


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.

Ben

On Thu, Mar 28, 2019 at 11:57 AM Neal Becker <ndbecker2 at gmail.com> 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
> 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/a7f494cc/attachment.html>


More information about the Matplotlib-users mailing list