is there a general code that can export Matplotlib plots to .stl?

577 Views Asked by At

I have already downloaded the Numpy-stl library but I am not sure how a general export would work for a simple code for example a cube? So, if I plot a Cube in Matplotlib, and want to export it to an .stl file to be able to open in CAD, how should I do it? I would also appreciate if someone can kindly explain what triangulation is about!! I am new to coding..

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations


fig = plt.figure()

ax = fig.gca(projection='3d')

ax.set_aspect("auto")

# draw cube

r = [-1, 2]

for s, e in combinations(np.array(list(product(r, r, r))), 2):

    if np.sum(np.abs(s-e)) == r[1]-r[0]:

        ax.plot3D(*zip(s, e), color="b")
0

There are 0 best solutions below