Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Customizing the wireframe / strides of a 3D plot

I am experimenting with 3D plotting to see how I can customize the output. In particular, I am trying to obtain something more similar to how Mathematica or Wolfram Alpha do things.

For example, I plotted Taubin's heart surface:

$$ \left(x^2+\frac{9 y^2}{4} + z^2 - 1\right)^3-x^2 z^3 - \frac{9 y^2 z^3}{80} = 0 $$

Using the following code:

var("x y z")

f = (x^2 + 2.25*y^2 + z^2 - 1)^3 - (x^2)*(z^3) - 0.1125*(y^2)*(z^3)
xint = (x, -1.5, 1.5)
yint = (y, -1.5, 1.5)
zint = (z, -1.5, 1.5)

my_plot = implicit_plot3d(f, xint, yint, zint, opacity=.7, mesh=2)
my_plot.show()

http_i.imgur .com/DbLGA50.png

The mesh corresponds to the triangulation of points that Sage performs on the data calculated with implicit_plot3d. However, Wolfram Alpha gives a different result (https_www.wolframalpha .com/input/?i=heart+surface), because it does not use all the edges of the triangulation:

http_i.imgur .com/VZtyWql.gif

What I think they are doing is they are using a high number of points to draw the surface, however they are "slicing" the object with planes parallel to the three axes (at fixed distances) to draw the contours.

How can I replicate these lines?

Matplotlib calls them "strides" as documented for Axes3d.plot_surface (http_matplotlib .org/mpl_toolkits/mplot3d/tutorial.html#surface-plots). My final goal is exporting 3D vector drawings which I managed to do with Matplotlib thanks to the numpy-stl package (https_github .com/WoLpH/numpy-stl):

my_plot.triangulate()
my_plot.save("/tmp/test.stl")
from mpl_toolkits import mplot3d
from matplotlib import pyplot

# Create a new plot
figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)

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

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

# Show the plot to the screen
pyplot.show()
pyplot.savefig("/home/andrea/Scrivania/wow.pdf")

In this case the presence of too much grid lines looks even worse:

http_i.imgur .com/s0LniGy.png
click to hide/show revision 2
No.2 Revision

Customizing the wireframe / strides of a 3D plot

I am experimenting with 3D plotting to see how I can customize the output. In particular, I am trying to obtain something more similar to how Mathematica or Wolfram Alpha do things.

For example, I plotted Taubin's heart surface:

$$ \left(x^2+\frac{9 y^2}{4} + z^2 - 1\right)^3-x^2 z^3 - \frac{9 y^2 z^3}{80} = 0 $$

Using the following code:

var("x y z")

f = (x^2 + 2.25*y^2 + z^2 - 1)^3 - (x^2)*(z^3) - 0.1125*(y^2)*(z^3)
xint = (x, -1.5, 1.5)
yint = (y, -1.5, 1.5)
zint = (z, -1.5, 1.5)

my_plot = implicit_plot3d(f, xint, yint, zint, opacity=.7, mesh=2)
my_plot.show()

http_i.imgur .com/DbLGA50.png

The mesh corresponds to the triangulation of points that Sage performs on the data calculated with implicit_plot3d. However, Wolfram Alpha gives a different result (https_www.wolframalpha .com/input/?i=heart+surface), (https://www.wolframalpha.com/input/?i=heart+surface), because it does not use all the edges of the triangulation:

http_i.imgur http://i.imgur .com/VZtyWql.gif

What I think they are doing is they are using a high number of points to draw the surface, however they are "slicing" the object with planes parallel to the three axes (at fixed distances) to draw the contours.

How can I replicate these lines?

Matplotlib calls them "strides" as documented for Axes3d.plot_surface (http_matplotlib .org/mpl_toolkits/mplot3d/tutorial.html#surface-plots). (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots). My final goal is exporting 3D vector drawings which I managed to do with Matplotlib thanks to the numpy-stl package (https_github .com/WoLpH/numpy-stl):(https://github.com/WoLpH/numpy-stl):

my_plot.triangulate()
my_plot.save("/tmp/test.stl")
from mpl_toolkits import mplot3d
from matplotlib import pyplot

# Create a new plot
figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)

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

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

# Show the plot to the screen
pyplot.show()
pyplot.savefig("/home/andrea/Scrivania/wow.pdf")

In this case the presence of too much grid lines looks even worse:

http_i.imgur http://i.imgur .com/s0LniGy.png

Customizing the wireframe / strides of a 3D plot

I am experimenting with 3D plotting to see how I can customize the output. In particular, I am trying to obtain something more similar to how Mathematica or Wolfram Alpha do things.

For example, I plotted Taubin's heart surface:

$$ \left(x^2+\frac{9 y^2}{4} + z^2 - 1\right)^3-x^2 z^3 - \frac{9 y^2 z^3}{80} = 0 $$

Using the following code:

var("x y z")

f = (x^2 + 2.25*y^2 + z^2 - 1)^3 - (x^2)*(z^3) - 0.1125*(y^2)*(z^3)
xint = (x, -1.5, 1.5)
yint = (y, -1.5, 1.5)
zint = (z, -1.5, 1.5)

my_plot = implicit_plot3d(f, xint, yint, zint, opacity=.7, mesh=2)
my_plot.show()

http_i.imgur .com/DbLGA50.png

The mesh corresponds to the triangulation of points that Sage performs on the data calculated with implicit_plot3d. However, Wolfram Alpha gives a different result (https://www.wolframalpha.com/input/?i=heart+surface), because it does not use all the edges of the triangulation:

http://i.imgur .com/VZtyWql.gif

What I think they are doing is they are using a high number of points to draw the surface, however they are "slicing" the object with planes parallel to the three axes (at fixed distances) to draw the contours.

How can I replicate these lines?

Matplotlib calls them "strides" as documented for Axes3d.plot_surface (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots). My final goal is exporting 3D vector drawings which I managed to do with Matplotlib thanks to the numpy-stl package (https://github.com/WoLpH/numpy-stl):

my_plot.triangulate()
my_plot.save("/tmp/test.stl")
from mpl_toolkits import mplot3d
from matplotlib import pyplot

# Create a new plot
figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)

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

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

# Show the plot to the screen
pyplot.show()
pyplot.savefig("/home/andrea/Scrivania/wow.pdf")

In this case the presence of too much grid lines looks even worse:

http://i.imgur .com/s0LniGy.png