Ask Your Question

plotting f(x,y)=x/y also plots the plane y=0 instead of being undefined

asked 2020-10-29 13:13:50 +0200

Qdemourgues gravatar image

when i plot f(x,y)=x/y plot3D additionally draws the plane y=0... thus the level curves become crosses instead of lines ... Here is my code :

from sage.plot.plot3d.plot3d import axes
P = axes(2, color='black')
for h in levels:

Additionally i would like to specify the range of z (i.e. between -10 and 10), and i cannot find how to do that in the manuel...

edit retag flag offensive close merge delete


You can restrict the z-range a posteriori like this

....: P=plot3d(f(x,y),(x,-4,4),(y,-4,4),color='khaki',opacity=0.7) 
....: P=P.add_condition(lambda x,y,z:abs(z)<10)
FrédéricC gravatar imageFrédéricC ( 2020-11-05 21:10:12 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-10-29 23:02:30 +0200

Emmanuel Charpentier gravatar image

An explanation rather than a solution:

This is best understood by extrapolation from the <2D case.

sage: plot(1/x,(x, -4,4), ymin=-4, ymax=4, axes=False, frame=True)

plots a (section of) hyperbola and an almost vertical line around x=0. this is a byproduct of the protting algorithm, hich computes plot_points points of the curve and interpolates a curve between them. The almost vertical line is what remains of the interpolated segment between the lats point with x<0 and the first point with x>0after clipping in the plot limits. This artefact can be avoided by requestiong plot's algorithm to fetect the sign changes with the option detect_poles:

sage: plot(1/x,(x, -4,4), ymin=-4, ymax=4, axes=False, frame=True, detect_poles=True)

Similarly, plot3d (and implicit_plot3d) compute plot_points^2 surface points and interpolates surface elements between them. The plane segments you see are the clipped remains of these surface elements around y=0.

Unfortunately, these 3D plot functions do not have a detect_poles option (which would be somewhat nontrivial to write in the 3D case, anyway...). And I am not aware of any easy way to "clip off" these surface elements straddling the discontinuity.

In this specific case, one could work around the difficulty by parametrically plotting the function in cylindrical or spherical coordinates, avoiding the discontinuity region. An approximation can be obtained by :

                             (r,0,4),(theta,-pi/2+1e-3,pi/2-1e3)) + 

which can be clipped off afterwards (I can't remember how ATM, but this exists...).


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-10-29 13:02:14 +0200

Seen: 115 times

Last updated: Oct 29 '20