0

I'm trying to create a scatterplot of the data in scores where the values above a threshold are colored red. I'm having issues with getting the colors to show accordingly. I would also like to shade the background of the figure for the indices specified in labels, which is a list of 0s and 1s the length of the dataframe. Below is the code I have so far. Thanks in advance for the help!

import pandas
...

values = pandas.DataFrame({"scores":scores, "labels":labels, "indices":range(len(labels))})

# plot alerts in red, others in black
alertValues = values.iloc[scores[scores >= threshold].index]

ax = alertValues.plot(kind="scatter", x="indices", y="scores", c='r',
  marker='.', s=5, alpha=0.5)
values.plot(kind="scatter", x="indices", y="scores", c='r',
  marker='.', s=5, alpha=0.5, ax=ax)

# show plot
plt.title(fileName)
plt.show()
BoltzmannBrain
  • 5,082
  • 11
  • 46
  • 79
  • Can you describe what, if any, type of output you are getting? For example, are you displaying a graph, but only the coloring is off or are you not able to see a graph? – alacy Jan 30 '15 at 01:44
  • @aus_lacy I'm able to see the plot, but all data points are black. – BoltzmannBrain Jan 30 '15 at 06:15
  • You could use a gray scale but then define the colors yourself (see http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable) or you could just plot all of the values under the threshold as one color and then plot the values above the threshold onto the same plot, but in the other color. In regards to shading specific indices I'm not sure of how to do something like that which isn't to say it's not possible, just that I'm not aware of a way to do it. – alacy Jan 30 '15 at 14:03
  • @aus_lacy the 2nd option you mention is what I'm attempting, but it's not working properly... – BoltzmannBrain Jan 30 '15 at 19:48
  • http://stackoverflow.com/questions/11190735/python-matplotlib-superimpose-scatter-plots – alacy Jan 30 '15 at 20:03

1 Answers1

1

The issue is with calling the plot function from a pandas DataFrame. Much better to just use pyplot with lists:

plt.figure()
plt.scatter(indices, scores)
plt.scatter(fooIndices, fooScores)
plt.show()
BoltzmannBrain
  • 5,082
  • 11
  • 46
  • 79