I would like to create layered heatmaps using (x,y,z) coordinates and a fourth dimension, color-based, to correlate to intensity.
Each layer-related data sits in a text file with columns of x, y, z and G. The delimiter is white space. Apologies if it does not present properly.
XA 200 600 1200 1800 2400 3000 200 600 1200 1800 2400 3000
YA 0 0 0 0 0 0 600 600 600 600 600 600
ZA 600 600 600 600 600 600 600 600 600 600 600 600
GA 1.27 1.54 1.49 1.34 1.27 1.25 1.28 1.96 1.12 1.06 1.06 1.06
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
data = np.load(filename)
x = np.linspace(0,2400,num=6)
y = np.linspace(0,2400,num=11)
X,Y=np.meshgrid(x,y)
Z = data[:,:,0] * 1e-3
plt.contourf(X,Y,Z)
plt.colorbar()
How to read text files, create and superimpose heatmaps along the Z-axis?
Say you have two txt files, namely data-z600.txt and data-z1200.txt, in the same folder as your python script, whose contents are exactly
data-z600.txt (yours)
and data-z1200.txt (invented on purpose)
Let's import all the required libraries
and define
grids_maker
, a function that does the job of preparing data contained in a given file, here targeted via thefilepath
argument.Let's use
grids_maker
over our list of files and get the extrema of each file's 4th dimension.Let's create our (all-file unifying) color-scale
... and finally make/show the plot