ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 09 Nov 2010 23:54:51 +01002D plotting in sage looks wronghttps://ask.sagemath.org/question/7757/2d-plotting-in-sage-looks-wrong/I am a beginner using sage, and I have encountered a problem using the plot function.
Plotting a simple sine or cosine function is not very precise:
t=var('t')
v=plot(sin(t),-pi,pi
The function is clearly positive in t=-pi, where it should be zero.
The mistake becomes even more clear when setting line thickness to 99:
t=var('t')
v=plot(sin(t),-pi,pi,thickness=99)
In this case when x=0 the line is crossing 1 in the upper side and not -1 in the lower side.
This problem occurs in all functions i have encountered so far, as if the function is displayed 1 or 2 pixels off.
It's even worse when plotting arrows:
plot(arrow((0,0), (2,3)))
Here the arrow is clearly not starting in (0,0) as it should.
Is there a solution for this kind of problem?Mon, 08 Nov 2010 17:57:25 +0100https://ask.sagemath.org/question/7757/2d-plotting-in-sage-looks-wrong/Answer by kcrisman for <p>I am a beginner using sage, and I have encountered a problem using the plot function.
Plotting a simple sine or cosine function is not very precise:</p>
<pre><code>t=var('t')
v=plot(sin(t),-pi,pi
</code></pre>
<p>The function is clearly positive in t=-pi, where it should be zero.
The mistake becomes even more clear when setting line thickness to 99:</p>
<pre><code>t=var('t')
v=plot(sin(t),-pi,pi,thickness=99)
</code></pre>
<p>In this case when x=0 the line is crossing 1 in the upper side and not -1 in the lower side.</p>
<p>This problem occurs in all functions i have encountered so far, as if the function is displayed 1 or 2 pixels off.
It's even worse when plotting arrows:</p>
<pre><code> plot(arrow((0,0), (2,3)))
</code></pre>
<p>Here the arrow is clearly not starting in (0,0) as it should.</p>
<p>Is there a solution for this kind of problem?</p>
https://ask.sagemath.org/question/7757/2d-plotting-in-sage-looks-wrong/?answer=11769#post-id-11769This is a known issue. We have just upgraded to matplotlib 1.0.0 in Sage-4.6.alpha0 (a prelease version), and there are some open tickets related to this. Essentially, matplotlib didn't allow specifying pixel width and pixel aspect ratio and a sort of anti-aliasing and a few other things all at once, at least not the way we were using it...
But essentially it's hard to ensure this kind of thing won't happen without breaking certain other things, due to the vagaries of computer graphics, apparently. See http://trac.sagemath.org/sage_trac/ticket/7808 for the issue itself.
I think this should answer your question, though perhaps not satisfactorily :( please feel free to comment on any of the Trac tickets with comments that will help us make it more perfect - especially with which of 1-3 you prefer in the ticket.Mon, 08 Nov 2010 20:32:30 +0100https://ask.sagemath.org/question/7757/2d-plotting-in-sage-looks-wrong/?answer=11769#post-id-11769Answer by Jason Grout for <p>I am a beginner using sage, and I have encountered a problem using the plot function.
Plotting a simple sine or cosine function is not very precise:</p>
<pre><code>t=var('t')
v=plot(sin(t),-pi,pi
</code></pre>
<p>The function is clearly positive in t=-pi, where it should be zero.
The mistake becomes even more clear when setting line thickness to 99:</p>
<pre><code>t=var('t')
v=plot(sin(t),-pi,pi,thickness=99)
</code></pre>
<p>In this case when x=0 the line is crossing 1 in the upper side and not -1 in the lower side.</p>
<p>This problem occurs in all functions i have encountered so far, as if the function is displayed 1 or 2 pixels off.
It's even worse when plotting arrows:</p>
<pre><code> plot(arrow((0,0), (2,3)))
</code></pre>
<p>Here the arrow is clearly not starting in (0,0) as it should.</p>
<p>Is there a solution for this kind of problem?</p>
https://ask.sagemath.org/question/7757/2d-plotting-in-sage-looks-wrong/?answer=11775#post-id-11775See [this thread](http://groups.google.com/group/sage-support/browse_thread/thread/cc11de47203a2f1d) on sage-support, where I believe this question was asked and answered pretty completely. The short answer is that it is a tradeoff between sharp graphics and rounding by one pixel when you have raster graphics (like png). To have fuzzier, but more correct graphics, do
import matplotlib
matplotlib.rcParams['path.snap'] = False
If you have vector graphics (like pdf), this is not an issue.
The arrow issue is a separate issue, since in Sage, arrows are automatically shortened by a bit. However, investigating this led to several bugfixes in arrows and [this Sage trac ticket](http://trac.sagemath.org/sage_trac/ticket/10242) for making arrows more precise when those bugfixes to matplotlib are eventually included in Sage.Tue, 09 Nov 2010 23:54:51 +0100https://ask.sagemath.org/question/7757/2d-plotting-in-sage-looks-wrong/?answer=11775#post-id-11775