Revision history [back]

Try this:

sage: parametric_plot((lambda t: t^3, lambda t: t), (0, 1))


Try this:The problem might be because "x to the power one third" is converted into "exponential of one third times logarithm of x" which does not make sense when x is zero, so the graph is missing the point at (0, 0) and only starts just after zero, but since the tangent at zero is vertical, this makes the graph start quite a bit off the x-axis.

One solution is to use a parametric plot instead.

sage: parametric_plot((lambda t: t^3, lambda t: t), (0, 1))


The problem might be because "x to the power one third" is converted into "exponential of one third times logarithm of x" which does not make sense when x is zero, so the graph is missing the point at (0, 0) and only starts just after zero, but since the tangent at zero is vertical, this makes the graph start quite a bit off the x-axis.

One solution is to use a parametric plot instead.

sage: parametric_plot((lambda t: t^3, lambda t: t), (0, 1))


Thinking about it more, the problem is probably because if not provided with a range of x values, Sage will plot in the range from 0 to 1, cutting it up into 200 points by default. Since it uses the integers 0 and 1 and not floating point 0 and 1, the points at which it evaluates the function end up being rationals, and the "power one third" produces algebraic numbers (probably non real ones because why not choose a non-real cube root).

So another workaround is to specify a plotting range with floating-point endpoints.

sage: plot(x^(1/3), (0., 1.))


[Edited after the question was updated, clarifying it is not "why does the graph not start at zero", but "why is the negative part missing".]

Together with the unsatisfactory plot, the command

sage: plot(x^(1/3))


gives some warnings:

verbose 0 (3797: plot.py, generate_plot_points)
WARNING: When plotting, failed to evaluate function at 100 points.
verbose 0 (3797: plot.py, generate_plot_points)
Last error message: 'can't convert complex to float'


They give a clue as to what goes wrong.

By default, plot plots on the interval $[-1, 1]$ using 200 points regularly spaced along that interval to evaluate the function being plotted.

The problem might warning that it "failed to evaluate function at 100 points", and the plot it produces, reveal that it failed to get a point to plot for all the negative values.

Here is how Sage computes powers one-third of negative numbers, depending on whether they are rational or floating-point:

sage: a = (-1)^(1/3)
sage: a
(-1)^(1/3)
sage: b = (-1.)^(1/3)
sage: b
0.500000000000000 + 0.866025403784439*I


And here is what happens when trying to convert them to floats (plot does that):

sage: float(a)
---------------------------------------------------------------------------
Traceback (most recent call last)
...
TypeError: can't convert complex to float
During handling of the above exception, another exception occurred:
TypeError: unable to simplify to float approximation
sage: float(b)
Traceback (most recent call last)
...
TypeError: unable to convert 0.500000000000000 + 0.866025403784439*I
to float; use abs() or real_part() as desired


To plot the real-cube-root function, i.e. the composition inverse of the $(x \mapsto x^3)$ bijection, there are various options.

One is indicated in @rburing's answer, and uses the sign and the absolute value to work around this limitation in Sage. It is actually part of the SageMath FAQ, see:

• [How do I plot the cube root (or other odd roots) for negative input?] (http://doc.sagemath.org/html/en/faq/faq-usage.html#how-do-i-plot-the-cube-root-or-other-odd-roots-for-negative-input)

One other option is to plot $x = y^3$ instead of $y = x^(1/3)$.

This can be because "x to the power one third" is converted into "exponential of one third times logarithm of x" which does not make sense when x is zero, so the graph is missing the point at (0, 0) and only starts just after zero, but since the tangent at zero is vertical, this makes the graph start quite a bit off the x-axis.

One solution is to use done using a parametric plot instead.plot:

sage: parametric_plot((lambda t: t^3, lambda t: t), (0, (-1, 1))


Thinking about it more, the problem is probably because if not provided

This can also be done using an implicit plot since the desired graph is the locus where $x - y^3$ is zero:

sage: implicit_plot(lambda x, y: x - y^3, (-1, 1), (-1, 1))


By default implicit plot comes with a range frame instead of axes.

sage: implicit_plot(lambda x, y: x values, Sage will plot
in the range from 0 to 1, cutting it up into 200 points by
default. Since it uses the integers 0 and 1 and not floating
point 0 and 1, the points at which it evaluates the function
end up being rationals, and the "power one third" produces
algebraic numbers (probably non real ones because why not
choose a non-real cube root). So another workaround is to specify a plotting range with
floating-point endpoints. sage: plot(x^(1/3), (0., 1.))
- y^3, (-1, 1), (-1, 1), axes=True)


One can additionally remove the frame:

sage: implicit_plot(lambda x, y: x - y^3, (-1, 1), (-1, 1), axes=True, frame=False)


[Edited after the question was updated, clarifying it is not "why does the graph not start at zero", but "why is the negative part missing".]

Together with the unsatisfactory plot, the command

sage: plot(x^(1/3))


gives some warnings:

verbose 0 (3797: plot.py, generate_plot_points)
WARNING: When plotting, failed to evaluate function at 100 points.
verbose 0 (3797: plot.py, generate_plot_points)
Last error message: 'can't convert complex to float'


They give a clue as to what goes wrong.

By default, plot plots on the interval $[-1, 1]$ using 200 points regularly spaced along that interval to evaluate the function being plotted.

The warning that it "failed to evaluate function at 100 points", and the plot it produces, reveal that it failed to get a point to plot for all the negative values.

Here is how Sage computes powers one-third of negative numbers, depending on whether they are rational or floating-point:

sage: a = (-1)^(1/3)
sage: a
(-1)^(1/3)
sage: b = (-1.)^(1/3)
sage: b
0.500000000000000 + 0.866025403784439*I


And here is what happens when trying to convert them to floats (plot does that):

sage: float(a)
---------------------------------------------------------------------------
Traceback (most recent call last)
...
TypeError: can't convert complex to float
During handling of the above exception, another exception occurred:
TypeError: unable to simplify to float approximation
sage: float(b)
Traceback (most recent call last)
...
TypeError: unable to convert 0.500000000000000 + 0.866025403784439*I
to float; use abs() or real_part() as desired


To plot the real-cube-root function, i.e. the composition inverse of the $(x \mapsto x^3)$ bijection, there are various options.

One is indicated in @rburing's answer, and uses the sign and the absolute value to work around this limitation in Sage. It is actually part of the SageMath FAQ, see:

One other option is to plot $x = y^3$ instead of $y = x^(1/3)$.

This can be done using a parametric plot:

sage: parametric_plot((lambda t: t^3, lambda t: t), (-1, 1))


This can also be done using an implicit plot since the desired graph is the locus where $x - y^3$ is zero:

sage: implicit_plot(lambda x, y: x - y^3, (-1, 1), (-1, 1))


By default implicit plot comes with a frame instead of axes.

sage: implicit_plot(lambda x, y: x - y^3, (-1, 1), (-1, 1), axes=True)

sage: implicit_plot(lambda x, y: x - y^3, (-1, 1), (-1, 1), axes=True, frame=False)