0

I have 4 columns in a dataframe which I would like to see whether there is a correlation. I thought it could give me some insight by ploting them in a 3D plot and then adding the 4th dimension as a heatmap, but I have no ideia how to add this heatmap linked to one column in a dataframe.

This is what I've got so far:

from mpl_toolkits.mplot3d import Axes3D  
fig = plt.figure(figsize=(12,12));
ax = fig.add_subplot(111, projection='3d');
ax.scatter(Series1,Series2,Series3); 

Which returns me this:

(https://i.stack.imgur.com/qRGMv.png)

So, there are points of Series1,Series2 and Series3 on it... but is there a way to add a heatmap or anything to distinguish from a Series4?

Bruno Takara
  • 11
  • 1
  • 6

1 Answers1

0

I figured out that there is a way to add a colormap by adding the c parameter, as in:

withcolormap = ax.scatter(Series1, Series2, Series3, c = Series4, cmap='gist_heat');

And then by ploting its colobar aside:

fig.colorbar(withcolormap, shrink=0.75);

As it gave me any insights, I wonder how to plot an animation of a rotating view of this plot, I tried it by doing this code:

from matplotlib.animation import FuncAnimation, PillowWriter

def rotation(i):
  ax = fig.add_subplot(111, projection='3d')
  ax.view_init(elev=30, azim=i);

ani = FuncAnimation(withcolormap, rotation, frames=range(0,360,10))

And then it returns an error:

AttributeError: 'Path3DCollection' object has no attribute 'canvas'
Bruno Takara
  • 11
  • 1
  • 6