Today I want to make 3d scatterplot with matplolib for my dataset. But when I would like to show the legend, only one item was displayed (the first one), I don't know to correct it.
There is my code :
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [13,20]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
data2['color'] = ["blue" if i > 0 else "red" for i in data2['Weaning_success']] #Create color column
x =data2['Fibrinogen']
y =data2['RR__root_mean_square']
z =data2['Weight gain']
scatter= ax.scatter(x, y, z, c=data2['color'], marker='o', s= 150, depthshade=True)
ax.set_xlabel('Fibrinogen')
ax.set_ylabel('RR__root_mean_square')
ax.set_zlabel('Weight gain')
plt.legend(labels=['Success', 'Failure'], bbox_to_anchor= (1.05, 0.5), loc= "lower left")
plt.show()
And this is the graph created :