# 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?

edit retag close merge delete

Sort by » oldest newest most voted

See this thread 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 for making arrows more precise when those bugfixes to matplotlib are eventually included in Sage.

more

This 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/ti... 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.

more