wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
628 stars 107 forks source link

Graph Generation is Blank #203

Closed abigailwilder closed 1 year ago

abigailwilder commented 2 years ago

Hello!

I am trying to do some simple testing to gain an understanding of how this package works. I have created a basic triangular prism and exported the stl file. I am now trying to use the provided code to create a new plot loading the stl file. When the code is run and what should be the figure pops up, it is entirely blank, not even showing the axes. Is there a reason for this? Is there something I have missed?

Thank you!

wolph commented 2 years ago

Hi,

It seems that the matplotlib API has changed slightly and the example doesn't work anymore. Luckily it's a quick fix: https://github.com/WoLpH/numpy-stl/commit/4523a4917782f17cfdec1b63cadc1be8714f2449

You can use this example instead:

from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot

# Create a new plot
figure = pyplot.figure()
axes = figure.add_subplot(projection='3d')

# Load the STL files and add the vectors to the plot
your_mesh = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors))

# Auto scale to the mesh size
scale = your_mesh.points.flatten()
axes.auto_scale_xyz(scale, scale, scale)

# Show the plot to the screen
pyplot.show()