Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib contourf3d plot_surface vs. trisurf

I'm trying to do this with my data that has the following structure:

 0.90000000   0.90000000 -2133.80472139
 0.90000000   0.95000000 -2133.84134433
 ...
 1.87500000   1.82500000 -2133.96171262
 1.87500000   1.87500000 -2133.95550450

With the following code, I've partially succeed. However, I can't plot the contours on the x-y, x-z and y-z planes. I had to use plot_trisurf since the plot_surface option doesn't work for this data (I really don't know why). Creating a np.meshgrid didn't help (after converting the lists to np.array).

import numpy as np
import sys
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

filename = sys.argv[1]

with open(filename+'.dat', 'r') as f:
    x = []
    y = []
    z = []
    for line in f:
        data = line.split()
        x.append((float(data[0])))
        y.append((float(data[1])))
        z.append((float(data[2])))

zz = [627.503*(i+2134.070983645239) for i in z]

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, zz, cmap=cm.jet, linewidth=0.1)
ax.dist=12
ax.view_init(30, 45)
ax.set_xlim(0.9, 1.9)
ax.set_ylim(0.9, 1.9)
ax.set_zlim(0, 170)
plt.show()

enter image description here

Do you have, please, any ideas on how could I have the contour on the x-y place and the projections on the x-z and y-z ones?

like image 727
Hugo Santos Silva Avatar asked Jun 13 '16 15:06

Hugo Santos Silva


1 Answers

You have to use triangular contour and filled triangular contour: tricontour and tricontourf: http://matplotlib.org/examples/pylab_examples/tricontour_demo.html

I have added to you plot projection of a surface to XY with tricontourf:

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, zz, cmap=cm.jet, linewidth=0.1)
# projection of a surface to XY
ax.tricontourf(x, y, zz, zdir='z', offset=-1, cmap=cm.coolwarm)

ax.dist=12
ax.view_init(30, 45)
ax.set_xlim(0.9, 1.9)
ax.set_ylim(0.9, 1.9)
ax.set_zlim(0, 170)
plt.show()

enter image description here

like image 87
Serenity Avatar answered Nov 04 '22 23:11

Serenity