# Controlling tick marks in plots

I'm trying to do a plot and control the tick marks. I'd like to have tick marks on the horizontal axis only at 3 and 6. Here is the code I'm using:

p=plot(f(v),(v,2,12),detect_poles='show',ymin=-2,ymax=50)
p+=text('vc',(3,-1.5),color='black')
p+=text('2vc',(6,-1.5),color='black')
show(p)


I cannot seem to get the "tick" option to be recognized here by sage. Can anyone help?

Note: I am running Sage 4.4. I am starting to think this is fixed in 4.6. Is that correct?

edit retag close merge delete

Sort by ยป oldest newest most voted

You can use the FormatStrFormatter of matplotlib.

sage: from matplotlib import ticker
sage: TT = ticker.FormatStrFormatter('%.7f')
sage: plot(1-2*x^2,x,.707106,.707107, tick_formatter=TT)

more

This is something that comes up enough it should be in documentation. If I didn't destroy my Sage build while attempting to upgrade I'd try to review that.

( 2014-02-01 14:05:47 -0600 )edit

It's already mentioned in the documentation to look up mpl's ticker documentation.

( 2014-02-02 18:24:19 -0600 )edit

No, I mean this specific example, sorry. Because mpl's documentation is sometimes hard to convert to Sage notation.

( 2014-02-03 03:50:11 -0600 )edit

You are correct that this should work now in recent versions. Check out link text and search for the word 'ticks'. I don't have your original function $f$, but it shouldn't be hard to create.

sage: plot(x^2, (x, 2, 12), ticks=[[3,6],None])


We need to get this in plot? ... :(

more

How can I get precise tick marks? E.g if I execute

plot(1-2*x^2,x,.707106,.707107)

then ALL of the tick marks on the x axis read 7.071e-1. How can I get the tick marks to write out to seven decimal places? I've tried messing around with the ticks and tick_formatter specifications, but I get either no improvement or an error message.

Can anyone help? Thanks.

more