1

I'm trying to plot multiple pairs of data on a single scatter plot, each colored by a different third variable array. The coloring seems to work for the first plot, then fails for the second and third.

Any help would be appreciated

import matplotlib.pyplot as plt

jet=plt.get_cmap('jet')

x = [1,2,3,4]
y = [1,2,3,4]
z = [1,1,1,1]

a = [2,3,4,5]
b = [1,2,3,4]
c = [2,2,2,2]

d = [3,4,5,6]
e = [1,2,3,4]
f = [3,3,3,3]

plt.scatter(x, y, s=100, c=z, cmap=jet)
plt.scatter(a, b, s=100, c=c, cmap=jet)
plt.scatter(d, e, s=100, c=f, cmap=jet)

plt.clim(0,5)
plt.colorbar()
plt.show()
3
  • I have seen that. Those examples are for a single scatter plot. My coloring fails for subsequent scatter plots. Commented Mar 23, 2015 at 0:00
  • why do you want to color using the third variable since all values in the color lists are the same? Commented Mar 23, 2015 at 0:00
  • Good point, I just used this as a mockup of my real data where I need the arrays separate to control the symbols and create a legend (the data is from analyses on the different samples) Commented Mar 23, 2015 at 0:03

2 Answers 2

2

I have removed the plt.clim(0,5) line and added minimal and maximal values for all plots and that seems to work.

import matplotlib.pyplot as plt

jet=plt.get_cmap('jet')

x = [1,2,3,4]
y = [1,2,3,4]
z = [1,1,1,1]

a = [2,3,4,5]
b = [1,2,3,4]
c = [2,2,2,2]

d = [3,4,5,6]
e = [1,2,3,4]
f = [3,3,3,3]

plt.scatter(x, y, s=100, c=z, vmin=1, vmax=5, cmap=jet)
plt.scatter(a, b, s=100, c=c, vmin=1, vmax=5, cmap=jet)
plt.scatter(d, e, s=100, c=f, vmin=1, vmax=5, cmap=jet)

plt.colorbar()
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

2

The problem is that your colormap is being renormalized for each of your plot commands. Also. As a matter of style, jet is basically never the right colormap to use. So try this:

import matplotlib.pyplot as plt

jet=plt.get_cmap('coolwarm')

x = [1,2,3,4]
y = [1,2,3,4]
z = [1,1,1,1]

a = [2,3,4,5]
b = [1,2,3,4]
c = [2,2,2,2]

d = [3,4,5,6]
e = [1,2,3,4]
f = [3,3,3,3]

plt.scatter(x, y, s=100, c=z, cmap=jet, vmin=0, vmax=4)
plt.scatter(a, b, s=100, c=c, cmap=jet, vmin=0, vmax=4)
plt.scatter(d, e, s=100, c=f, cmap=jet, vmin=0, vmax=4)

plt.clim(0,5)
plt.colorbar()
plt.show()

Makes a nice plot: enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.