Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color scatter plot points based on a value in third column?

I am currently plotting a scatterplot based on two columns of data. However, I would like to color the datapoints based on a class label that I have in a third column.

The labels in my third column are either 1,2 or 3. How would I color the scatter plot points based on the values in this third column?

plt.scatter(waterUsage['duration'],waterUsage['water_amount'])
plt.xlabel('Duration (seconds)')
plt.ylabel('Water (gallons)')
like image 333
Gary Avatar asked Mar 08 '17 00:03

Gary


People also ask

How do I change the color of a data point in excel based on value?

Right click the data series on the chart and choose Format Data Series, Marker Fill, and check Vary Color by point. Was this reply helpful?

How do you color a specific dot on a scatter plot in Excel?

To edit the colours, select the chart -> Format -> Select Series A from the drop down on top left. In the format pane, select the fill and border colours for the marker.

How do you make a point on a scatter plot different colors?

On the Format tab, in the Current Selection group, click Format Selection. tab, expand Fill, and then do one of the following: To vary the colors of data markers in a single-series chart, select the Vary colors by point check box.


1 Answers

The scatter function happily takes a list of numbers representing color. You can play with a colormap, too, if you want (but you don't have to):

plt.scatter(waterUsage['duration'], waterUsage['water_amount'],\
            c=waterUsage['third_column'], cmap=plt.cm.autumn)
like image 197
DYZ Avatar answered Sep 18 '22 17:09

DYZ