0

I have a dataframe with five columns. I have written a code for three-dimensional scatter for three columns from it:

from mpl_toolkits import mplot3d

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = plt.axes(projection='3d')

ax = plt.axes(projection='3d')
ax.scatter(df[['col1']],df[['col2']],df[['col3']], cmap='viridis', linewidth=0.5)

It gives me scatter like this:

enter image description here

But I have 5 columns and i want to see all possible 3D scatter plots from them: (col1, col4, col5), (col2, col3, col5), .....

How could i do that?

  • If you are looking for a correlation between some variables, it's more common to use a [scatter plot matrix](https://en.wikipedia.org/wiki/Scatter_plot#Scatter_plot_matrices). Fortunately Pandas has a nice [`scatter_matrix(df)`](https://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html#scatter-matrix-plot) method – gboffi Nov 30 '20 at 23:26

1 Answers1

0

What about using itertools?

from itertools import combinations 
com = combinations(['col1','col2','col3','col4','col5'], 3)  
for i in com:  
    print(i)

Something like:

from itertools import combinations 
comb = combinations(['col1','col2','col3','col4','col5'], 3)  
for i in list(comb): 
    fig = plt.figure()
    ax = plt.axes(projection='3d')
    ax.scatter(df[[i[0]]],df[[i[1]]],df[[i[2]]], cmap='viridis', linewidth=0.5)
nuxie
  • 48
  • 6