Ask Your Question

2D plotting in sage looks wrong

asked 2010-11-08 10:57:25 -0500

Kabi gravatar image

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:


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:


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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2010-11-09 16:54:51 -0500

Jason Grout gravatar image

updated 2010-11-09 16:55:32 -0500

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.

edit flag offensive delete link more

answered 2010-11-08 13:32:30 -0500

kcrisman gravatar image

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 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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2010-11-08 10:57:25 -0500

Seen: 332 times

Last updated: Nov 09 '10