How to plot 3d surfaces as 2d lines using matplotlib

  matplotlib, plot, python

I have some surfaces and want to plot them using matplotlib. Each surface has four corners stored in a numpy arrays:

import numpy as np
points = np.array ([[[472.983284, 114.5,-1792.],
        [720.65216064, 1535.5, -1792.],
        [1500.20385742, 1535.5, -1008.],
        [1252.39562988, 114.5, -1008.]],
       [[590.38764954, 114.5, -1792.],
        [652.08530426, 1535.5, -1792.],
        [1405.10574341, 1535.5, -1008.],
        [1343.39660645, 114.5, -1008.]],
       [[679.80918884, 114.5, -1792.],
        [568.60767365, 1535.5, -1792.],
        [1323.85253906, 1535.5, -1008.],
        [1435.00518799, 114.5, -1008.]]])

Then, I am using the following code to have a 3d plot of the surfaces:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import (AutoMinorLocator, MultipleLocator)
%matplotlib qt5
fig = plt.figure()
ax = fig.add_subplot (111, projection="3d")
for i in points:
    x = np.array([[i[0,0], i[-1,0]], [i[1,0], i[2,0]]])
    y = np.array([[i[0,1], i[-1,1]], [i[1,1], i[2,1]]])
    z = np.array([[i[0,2], i[-1,2]], [i[1,2], i[2,2]]])
    ax.plot_surface(x, y, z)
ax.set_xlabel('X'); ax.set_ylabel('Y'); ax.set_zlabel('Z')
plt.show()

it gives me a 3d plot:

enter image description here
But I want also to have a 2d plot from 3d surfaces. This line of code gives me a view but still the plot is 3d:

ax.view_init(azim=270, elev=0)

But I have no idea how to create real 2d plot from the 3d one. I mean I want to have lines insted of surfaces. For example I want to say in a defined value of y axis, give me a 2d plot of existing surfaces as lines. In the second fig I have shown lines instead of surfaces when y equals 114.5. The plot I want looks like spaghetti plots (like last unrealistic plot in my post).
In advance I do appreciate any help.

enter image description here
enter image description here

Source: Python Questions

LEAVE A COMMENT