Implicit plot with squaring and absolute value produces empty plot

asked 2017-08-17 17:36:31 -0500

Doeke gravatar image

The following code:

sage: x,y = var('x y')
sage: implicit_plot(x, (x,-2,2), (y,-2,2))

produces a plot of a straight line along the coordinate y-axis as expected (it should plot the curve $x = 0$).

However, this very similar code:

sage: implicit_plot(x^2, (x,-2,2), (y,-2,2))

produces a plot with nothing on it, even though it should plot the curve $x^2 = 0$ which is clearly the same as the above curve.

This problem seems to persist with any function $f(x, y)$, i.e., in the following code,

f(x, y) = [some expression involving x and y]
sage: implicit_plot(f(x, y), [x scale], [y scale])
sage: implicit_plot(f(x, y)^2, [x scale], [y scale])

the second line produces a nonempty plot while the third line produces an empty plot. Replacing f(x,y)^2 with abs(f(x,y)) or even abs_symbolic(f(x,y)) has the same effect: they all produce empty plots.

The problem persists when one replaces implicit_plot with implicit_plot3d.

What's going on? Is this a bug?

edit retag flag offensive close merge delete

Comments

Looking in the code via ??implicit_plot we get the relevant lines...

if options['fill'] is True:
    # many further lines
    if not is_Expression(f):
        return region_plot(lambda x, y: f(x, y) < 0, xrange, yrange,
                           borderwidth=linewidths, borderstyle=linestyles,
                           incol=incol, bordercol=bordercol,
                           **options)
    else:
        return region_plot(f < 0, xrange, yrange, borderwidth=linewidths,
                           borderstyle=linestyles,
                           incol=incol, bordercol=bordercol,

and it is hard to arrange $f<0$ passing a square to the region_plot...

dan_fulea gravatar imagedan_fulea ( 2017-08-18 16:36:34 -0500 )edit

This leads one to investigate a similar phenomenon:

region_plot(x==0, (-2, 2), (-2, 2), axes=False)

produces a line on the coordinate y-axis, but

region_plot(x^2==0, (-2, 2), (-2, 2), axes=False)

produces an empty plot.

Doeke gravatar imageDoeke ( 2017-08-18 19:16:15 -0500 )edit