I have been searching for 3D plots in python with seaborn and haven\'t seen any. I would like to 3D plot a dataset that I originally plotted using seaborn pairplot. Can anyone
There is no color palette specification for fig 2 but it looks like it is the Paired qualitative colormap from matplotlib (from here). So you need to specify that in your code for the 3D plot with the cmap
argument and with the palette
option in your pairplot.
The legend is harder. You can make one from legend_elements. Better explained here.
So your code would look like this (I got rid of the unused imports):
import seaborn as sns, numpy as np, pandas as pd, random
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
sns.set_style("whitegrid", {'axes.grid' : False})
fig = plt.figure(figsize=(6,6))
ax = Axes3D(fig)
x = np.random.uniform(1,20,size=20)
y = np.random.uniform(1,100,size=20)
z = np.random.uniform(1,100,size=20)
g = ax.scatter(x, y, z, c=x, marker='o', depthshade=False, cmap='Paired')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
# produce a legend with the unique colors from the scatter
legend = ax.legend(*g.legend_elements(), loc="lower center", title="X Values", borderaxespad=-10, ncol=4)
ax.add_artist(legend)
plt.show()