Ask Your Question

Lazza's profile - activity

2020-04-23 23:32:20 +0100 received badge  Nice Question (source)
2019-04-14 13:19:48 +0100 received badge  Famous Question (source)
2017-09-04 22:26:24 +0100 received badge  Notable Question (source)
2017-01-11 21:59:06 +0100 received badge  Popular Question (source)
2016-09-27 14:43:08 +0100 received badge  Supporter (source)
2016-09-27 14:42:24 +0100 received badge  Editor (source)
2016-09-19 22:30:26 +0100 received badge  Student (source)
2016-09-18 22:02:42 +0100 asked a question How do I plot a function undefined in some areas?

I am trying to plot f(x,z) which is undefined in some areas. When I try to plot some other function, I can get it to work easily because Sage restricts the plot to the area where the function is real. E.g.:

plot3d(sqrt(1-x^2-y^2), (x,-5,5), (y,-5,5))

The border is a bit weird, but it works. I cannot get a working plot with my code, however. I also tried to wrap the function with a try ... except statement but I don't know what to return:

var("x y z")
def wrap(exp, a, b):
    try:
        return exp(x=a, z=b)
    except ValueError:
        return None

plot3d(lambda x,y: wrap(f, x, y), (x, -t, t), (y, -t, t)).show(aspect_ratio=1)

My function is f and it contains variables x and z.

2016-06-28 15:44:17 +0100 commented answer Customizing the wireframe / strides of a 3D plot

Thanks for your answer! Unfortunately I cannot upvote it yet. I have tweaked it a bit, obtaining this: sagecell.sagemath.org/?q=jrogwx. There is still the problem that those are actually "slices" of a 3D object and therefore have one side which is a line and one side which is thick (depending on the width). I will try to figure out how to draw just lines for them.

2016-06-26 19:00:37 +0100 commented question Customizing the wireframe / strides of a 3D plot

Sorry for the ugly formatting but the website wouldn't allow me to post the Q until I dropped all links. Someone with enough rep please fix the links and images. Thank you.

2016-06-26 19:00:36 +0100 asked a question 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()

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...), because it does not use all the edges of the triangulation:

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/mp...). My final goal is exporting 3D vector drawings which I managed to do with Matplotlib thanks to the numpy-stlpackage (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:

2012-12-19 05:56:21 +0100 commented answer A place to advertise Sage

I agree the font is the "problem". If you post the SVG, I could try to tweak it a bit. :)