0

I have a list of points (r1,r2) which I am plotting. For these points I have a certain error value 's' associated with each one of them. I want to assign a color with respect to what the error for each point is. For example red for highest error and blue for lowest error and also get a legend showing the range of colors. Can it be done? I have the following piece of code that I am trying:

fig, ax = plt.subplots()

data = scatter(r1, r2, c=s)

ax.set_title('Colormap for errors')
Aspro
  • 45
  • 2
  • 7
  • Possible duplicate of [Matplotlib scatterplot; colour as a function of a third variable](http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable) – stellasia Jun 21 '16 at 09:01

1 Answers1

0

How about this,

enter image description here


The source code is as follows. Refer to colormaps for more about colormaps.

import numpy as np
import matplotlib.pyplot as plt

x = np.random.rand(100)
y = np.random.rand(100)

plt.scatter(x, y, c=x, cmap='bwr')
plt.colorbar()
plt.show()
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134
  • This works just perfect. I have a follow up though, the value of 'c' here is normalized with respect to the maximum value of 'x'? – Aspro Jun 21 '16 at 09:17