ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 02 Feb 2014 03:11:17 -0600Tick Marks and Interceptshttp://ask.sagemath.org/question/10976/tick-marks-and-intercepts/Help! I'm trying to use Sage to plot x-intercepts, and there seems to be a problem when I try to zoom in too far. E.g. if I execute
plot(1-4*x^2,.4999,.5001,tick_formatter=.0001.n(digits=6))
then I get exactly what I expect, but if I execute
plot(1-4*x^2,.49999,.50001,tick_formatter=.00001.n(digits=7))
then I get this error message:
Traceback (click to the left of this block for traceback)
...
Unknown symbol: \verb (at char 0), (line:1, col:1)
Curiously, this seems to be directly related to the fact that my function is crossing the x axis on the domain in question. E.g. if I try
plot(1-4*x^2,1.49999,1.50001,tick_formatter=.00001.n(digits=7))
then everything comes out fine.
Any thoughts on what's going on and/or how to get around it?
Thanks.Sat, 01 Feb 2014 07:56:21 -0600http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/Answer by kcrisman for <p>Help! I'm trying to use Sage to plot x-intercepts, and there seems to be a problem when I try to zoom in too far. E.g. if I execute</p>
<p>plot(1-4*x^2,.4999,.5001,tick_formatter=.0001.n(digits=6))</p>
<p>then I get exactly what I expect, but if I execute</p>
<p>plot(1-4*x^2,.49999,.50001,tick_formatter=.00001.n(digits=7))</p>
<p>then I get this error message:</p>
<p>Traceback (click to the left of this block for traceback)
...
Unknown symbol: \verb (at char 0), (line:1, col:1)</p>
<p>Curiously, this seems to be directly related to the fact that my function is crossing the x axis on the domain in question. E.g. if I try</p>
<p>plot(1-4*x^2,1.49999,1.50001,tick_formatter=.00001.n(digits=7))</p>
<p>then everything comes out fine.</p>
<p>Any thoughts on what's going on and/or how to get around it?</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/?answer=15996#post-id-15996Good catch. My guess is that this is a matplotlib thing.
That said, [the graphics doc](http://www.sagemath.org/doc/reference/plotting/sage/plot/graphics.html) suggests this usage of `tick_formatter` is not really supported - it was intended for *symbolic* numbers, not floating point ones, though this is a very nice workaround for formatting. The following works (and doesn't look as nice):
plot(1-4*x^2,.49999,.50001,tick_formatter=[.00001.n(digits=7),None])
It turns out that the (Sage) issue is that floating point numbers in `RR` are also in `SR` the symbolic ring, which triggers this problem. But in principle this should still work - the problem is that matplotlib is being passed things that turn into `-4e^-5`. Note that this doesn't work either
plot(1-4*x^2,.50001,.50002,tick_formatter=.00001.n(digits=7))
ValueError:
\text{\texttt{{-}8e{-}05}}
^
Unknown symbol: \ttext (at char 0), (line:1, col:1)
so the problem is the addition of the `\text` when we already have the `\texttt` there.Sat, 01 Feb 2014 14:32:38 -0600http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/?answer=15996#post-id-15996Comment by kcrisman for <p>Good catch. My guess is that this is a matplotlib thing. </p>
<p>That said, <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/graphics.html">the graphics doc</a> suggests this usage of <code>tick_formatter</code> is not really supported - it was intended for <em>symbolic</em> numbers, not floating point ones, though this is a very nice workaround for formatting. The following works (and doesn't look as nice):</p>
<pre><code>plot(1-4*x^2,.49999,.50001,tick_formatter=[.00001.n(digits=7),None])
</code></pre>
<p>It turns out that the (Sage) issue is that floating point numbers in <code>RR</code> are also in <code>SR</code> the symbolic ring, which triggers this problem. But in principle this should still work - the problem is that matplotlib is being passed things that turn into <code>-4e^-5</code>. Note that this doesn't work either</p>
<pre><code>plot(1-4*x^2,.50001,.50002,tick_formatter=.00001.n(digits=7))
ValueError:
\text{\texttt{{-}8e{-}05}}
^
Unknown symbol: \ttext (at char 0), (line:1, col:1)
</code></pre>
<p>so the problem is the addition of the <code>\text</code> when we already have the <code>\texttt</code> there.</p>
http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/?comment=16358#post-id-16358Also, sorry this isn't a full answer - it's just as much me debugging out loud. I've opened http://trac.sagemath.org/ticket/15776 for this.Sat, 01 Feb 2014 14:35:34 -0600http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/?comment=16358#post-id-16358Comment by Slam for <p>Good catch. My guess is that this is a matplotlib thing. </p>
<p>That said, <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/graphics.html">the graphics doc</a> suggests this usage of <code>tick_formatter</code> is not really supported - it was intended for <em>symbolic</em> numbers, not floating point ones, though this is a very nice workaround for formatting. The following works (and doesn't look as nice):</p>
<pre><code>plot(1-4*x^2,.49999,.50001,tick_formatter=[.00001.n(digits=7),None])
</code></pre>
<p>It turns out that the (Sage) issue is that floating point numbers in <code>RR</code> are also in <code>SR</code> the symbolic ring, which triggers this problem. But in principle this should still work - the problem is that matplotlib is being passed things that turn into <code>-4e^-5</code>. Note that this doesn't work either</p>
<pre><code>plot(1-4*x^2,.50001,.50002,tick_formatter=.00001.n(digits=7))
ValueError:
\text{\texttt{{-}8e{-}05}}
^
Unknown symbol: \ttext (at char 0), (line:1, col:1)
</code></pre>
<p>so the problem is the addition of the <code>\text</code> when we already have the <code>\texttt</code> there.</p>
http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/?comment=15997#post-id-15997Certainly no need to apologize; this answer is very helpful. Thanks much, kcrisman.Sun, 02 Feb 2014 03:11:17 -0600http://ask.sagemath.org/question/10976/tick-marks-and-intercepts/?comment=15997#post-id-15997