### python

#### Plot 3D Surface from 2D lines in MatPlotLib python

I have a bunch of data which I am able to generate discrete 3D curves for, when plotted I just get a bunch of 2D lines at each z value, as in curve 1 (a) and (b), I want to be able to plot the surface that the 2D lines trace out, similar to what I did in curve 1 (a+b) but I want to plot the full surface, instead of the grid that is traced out and maybe add a color gradient to visualize the depth of each curve. Is this possible? I do not have data points inbetween z values, only for each discrete value of z. Curve 1 (a) and Curve 1(b) are both generated from exactly the same discrete x y and z values, in my code, I had to break it up into a horizontal and vertical portion, is there a way to plot the grid or surface without having to split it up like this? For each z value in z_vals, I have a corresponding plot (x,y) held in (zarr[:,0],zarr[:,1]). Additionally, I want to be able to plot an additional curve as in curve 2, but only when a radio button is pressed, or just an animation between curve 1 and curve 2, but on the same plot. This is my code so far, z_htxt = np.array(['z_h_0_05','z_h_0_06','z_h_0_07','z_h_0_08','z_h_0_09','z_h_0_1','z_h_0_125','z_h_0_15','z_h_0_175','z_h_0_2','z_h_0_225','z_h_0_25','z_h_0_275','z_h_0_3','z_h_0_325','z_h_0_35','z_h_0_375','z_h_0_4','z_h_0_45','z_h_0_5','z_h_0_55','z_h_0_6','z_h_0_65','z_h_0_7','z_h_0_75','z_h_0_8','z_h_0_85','z_h_0_9','z_h_0_93']) fig = plt.figure() ax = fig.add_subplot(221,projection='3d') ax2 = fig.add_subplot(222,projection='3d') ax3 = fig.add_subplot(223,projection='3d') ax4 = fig.add_subplot(224,projection='3d') z_vals = np.array([.05,.06,.07,.08,.09,.1,.125,.15,.175,.2,.225,.25,.275,.3,.325,.35,.375,.4,.45,.5,.55,.6,.65,.7,.75,.8,.85,.9,.93]) zarr = np.zeros([z_htxt.size,2,30]) for i in range(z_htxt.size): ltxt = z_htxt[i]+'_Q2_100.txt' zarr[i] = np.loadtxt(ltxt) ax2.plot(zarr[i,0],zarr[i,1],zs=z_vals[i],zdir='z',c='b') ax3.plot(zarr[i,0],zarr[i,1],zs=z_vals[i],zdir='z',c='b') ax.plot(zarr[:,0],zarr[:,1],z_vals,zdir='z',c='b') ax3.plot(zarr[:,0],zarr[:,1],z_vals,zdir='z',c='b') for j in range(z_htxt.size): ltxt = z_htxt[j]+'_Q2_1000.txt' zarr[j] = np.loadtxt(ltxt) ax4.plot(zarr[j,0],zarr[j,1],zs=z_vals[j],zdir='z',c='r') ax4.plot(zarr[:,0],zarr[:,1],z_vals,zdir='z',c='r') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_zlim(0,1) ax.view_init(elev=120,azim=-90) ax2.set_xlabel('X') ax2.set_ylabel('Y') ax2.set_zlabel('Z') ax2.set_zlim(0,1) ax2.view_init(elev=120,azim=-90) ax3.set_xlabel('X') ax3.set_ylabel('Y') ax3.set_zlabel('Z') ax3.set_zlim(0,1) ax3.view_init(elev=120,azim=-90) ax4.set_xlabel('X') ax4.set_ylabel('Y') ax4.set_zlabel('Z') ax4.set_zlim(0,1) ax4.view_init(elev=120,azim=-90) My code currently just pulls the x, y and z values from tables, then plots the 2D lines. I have tried using plot_surface() but to no avail since it tries to reference z values which I do not have data for. This might have been weird to explain, please let me know if I can clear anything up. The shapes of my (x,y,z) arrays (zarr[:,0],zarr[:,1],z_vals[:]) are: (29,30), (29,30), (29,) for x y and z respectively. If needed I can provide the full arrays. Thanks!

### Related Links

Sympy, plotting geometric entities yields either ImportError: no module named 'plot' or AttributeError: 'Circle' object has no attribute 'is_3D'

Select first row that meets certain condition

Splitting longer patterns using regex without losing characters Python 3+

Using python sdist to create a package that includes generated files in the build directory

Any elegant way to add a method to an existing object in python?

Setting cookies for static files using bottle.py

Python/Feedparser: reading RSS feed fails

How to generate a Torrent Magnet URI from a directory?

Python/Kivy camera widget error with opencv

Python3 - When exactly do you need to prepend “self._” to variable declarations within class methods? [duplicate]

how to tell python 3 to skip over non-digit characters from a csv file

writing numpy codes in cython with unknown dimensions

How to refresh django connection when inserting in SQL

How to get this enum if I only have a string representation in Python 2.7

How to escape Unicode in Python 3

Performance of timezone-aware Pandas DateTimeIndex