Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scatter plots with string arrays in matplotlib

this seems like it should be an easy one but I can't figure it out. I have a pandas data frame and would like to do a 3D scatter plot with 3 of the columns. The X and Y columns are not numeric, they are strings, but I don't see how this should be a problem.

X= myDataFrame.columnX.values #string
Y= myDataFrame.columnY.values #string
Z= myDataFrame.columnY.values #float

fig = pl.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, np.log10(Z), s=20, c='b')
pl.show()

isn't there an easy way to do this? Thanks.

like image 409
elelias Avatar asked Feb 28 '14 12:02

elelias


People also ask

Can you make a scatter plot with grouped data?

Adding a grouping variable to the scatter plot is possible. Furthermore, fitted lines can be added for each group as well as for the overall plot.

What is CMAP in scatter plot?

cmap: A map of colors to use in the plot.


1 Answers

Scatter does this automatically now (from at least matplotlib 2.1.0):

plt.scatter(['A', 'B', 'B', 'C'], [0, 1, 2, 1])   

scatter plot

like image 51
naught101 Avatar answered Sep 29 '22 20:09

naught101