Ask Your Question
1

2D plotting in sage looks wrong

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

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:

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

2 answers

Sort by ยป oldest newest most voted
1

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

Jason Grout gravatar image

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

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
1

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

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

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

Stats

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

Seen: 340 times

Last updated: Nov 09 '10