4D heat map in matplotlib
Asked Answered
B

2

6

I want to plot a 4D heatmap in Python through matplotlib, like this 4d map.

I have already a set of 3D grid points (x,y,z) and its corresponding function value f.

I am thinking of plotting it using plot_surface with x, y, z as the three required arrays, and alter the color gradient using f.

There is a way here to use f for the color gradient, but I have trouble plotting the 3D grid, which I will emphasize that the third dimension is independent of the first two. (The second link shows otherwise.)

Or are there any way to better visualize this 4D data using matplotlib?

Brotherton answered 15/2, 2017 at 12:58 Comment(2)
Since you only see 3 surfaces and not the whole volume, you could just display 3 standard heat maps in 3 different planes.Loney
I also thought of that. But I am thinking of visualizing it interactively (through plt.show()) where I can see all the sides of the cube. With this, it would be cumbersome to plot 6 heatmaps with custom grid arrays and checking the indices of f for each plane.Brotherton
T
1

Your data is of a slightly different form I imagine, but as long as you have a point for every thing you need to be plotted you could use something like they did here:

How to make a 4d plot using Python with matplotlib

Typify answered 15/2, 2017 at 13:40 Comment(2)
It is interesting in the example that the third dimension is a function of the first two, whereas the given data (in the problem) is that the third dimension is independent of the two.Brotherton
Not answering the question as @Brotherton has pointed outOrdzhonikidze
H
0

There aren't great existing ways to visualize true 4D functions (where the third dimension is independent of the first two as you described), so I wrote a small package plot4d. It should be able to help you visualize your function.

from plot4d import plotter
f = lambda x, y, z: sin(x)*y*cos(z)-x**3
z_range = np.linspace(0,2,10)
frame = plotter.Frame2D(xmin=0, xmax=1, ymin=0, ymax=1)
plotter.plot4d(f, z_range, frame=frame, func_name='f')

f.gif

Installation:

pip install plot4d
Huss answered 21/11, 2022 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.