1

How can I visualize a 4d data (loaded from a csv file) set using 3-d surface plots of the first 3 variables and the fourth variable as a slider?

kilojoules
  • 9,768
  • 18
  • 77
  • 149

1 Answers1

3

I've written a very small example highlighting the way you can achieve this:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider


nx = 100
ny = 100
nz = 100

data = np.random.rand(nx,ny,nz)

fig = plt.figure(1, figsize=(6,6))
main_ax = fig.add_axes([0.1,0.2,0.8,0.7])
slider_ax  = fig.add_axes([0.1,0.1,0.8,0.05])

main_ax.imshow(data[:,:,0], aspect='auto')


my_slider = Slider(slider_ax, 'layer', 0, nz, valinit=0, valfmt='%d')

def update(val):
    main_ax.imshow(data[:,:,int(val)], aspect='auto')
    plt.draw()

my_slider.on_changed(update)
plt.show()

In the previous examples I basically defined a 4D data set with random numbers. Then, I defined a Slider that pass the index of the slice that one might want to see and use imshow to do the plot. The callback method on_changed is responsible to call the update function when the value of the slider changes.

Alejandro
  • 3,263
  • 2
  • 22
  • 38