2D and 3D color maps from .xyz files

448 Views Asked by At

I'm a Python beginner and would like to create a 2D and 3D color map from data in a .xyz file as shown below :

The first column is x, the second y, and the third z.

At the end, I would like to get a 2D and 3D color maps as shown in the figures below.

I've tried a code for making 2D and 3D color map but it does not work. Could somoneone give me advices?

Here a secured link with data : https://filesender.renater.fr/?s=download&token=1d063c5a-6d26-48d8-974b-9a2ec80abec1

nb_lines=999
nb_columns=999

data = pd.read_csv("path",sep=' ',header=None).to_numpy()

#2D colormap

fig = plt.figure(figsize=(15,12))
ax = plt.subplot(1,1,1)
x=np.linspace(0,nb_columns,nb_columns)
y=np.linspace(0,nb_lines,nb_lines)
X,Y=np.meshgrid(x,y)
Xi, Yi = np.meshgrid(x, y)
cntr1 = ax.contourf(x, y, data, cmap="jet")
cbar = fig.colorbar(cntr1, ax=ax)


cbar.set_ticks(np.arange(70,140.01,10),[str(i) for i in np.arange(70,140.01,10)])
cbar.ax.tick_params(labelsize=25) 
ax.axis('on')



#3D colormap
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111, projection='3d')

surf=ax.plot_surface(X, Y, data, cmap='jet', antialiased=False)
cbar=fig.colorbar(surf, ax=ax)
cbar.set_ticks(np.arange(30,70.01,5),[str(i) for i in np.arange(30,70.01,5)])
cbar.ax.tick_params(labelsize=25) 
ax.axis('on')
ax.set_zlim()

3D 2D

0

There are 0 best solutions below