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()

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
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190328/a7f494cc/attachment.html&gt;

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
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190328/b83b57af/attachment.html&gt;

Hey Neal,

I modified your example a bit, is that what you want?

import numpy as np
import matplotlib.pyplot as plt

pts = 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.2

global_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 <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
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190328/79a549d7/attachment.html&gt;