I have a data frame with the following values and would like to create a 3D plot showing Recency, Frequency, and Monetary values labelled by the categories/loyalty levels (bronze, silver, gold, platinum) assigned to them. The relevant data looks as follows:
RFMScores.head()
the RFM_Catagory_Level
are numeric scores associated with the loyalty level
In attempting to make the chart, I used
figrfm2 = plt.figure()
ax = Axes3D(figrfm2)
xs = RFMScores.Recency
ys = RFMScores.Frequency
zs = RFMScores.Monetary
scores = RFMScores.RFM_Catagory_Level
scatter = ax.scatter(xs, ys, zs,c=scores,cmap='tab20b')
ax.set_title("3D plot")
ax.set_xlabel('Recency')
ax.set_ylabel('Frequency')
ax.set_zlabel('Monetary')
ax.legend(*scatter.legend_elements())
plt.show()
But the legend has the numeric values instead of the actual labels.
When I attempt to use the RFM_Loyalty_Level
such as this:
figrfm2 = plt.figure()
ax = Axes3D(figrfm2)
xs = RFMScores.Recency
ys = RFMScores.Frequency
zs = RFMScores.Monetary
scatter = ax.scatter(xs, ys, zs,c=RFMScores.RFM_Loyalty_Level,cmap='tab20b')
ax.set_title("3D plot")
ax.set_xlabel('Recency')
ax.set_ylabel('Frequency')
ax.set_zlabel('Monetary')
ax.legend(*scatter.legend_elements())
plt.show()
The chart is blank with no data. How do I fix this so that I have a chart, but with the label categories "platinum, gold, silver, bronze" instead of the numeric values that are in the legend?