Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I normally don't use sage's default plotting. But, I have pasted below a matplotlib example I found online and modified a few lines for clarity. The format of the x and y ticks is given is c-style format. Please let me know if you have any question. In general matplotlib is far more versatile than sage's default plotter and I use is to make plots.

from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

majorLocator   = MultipleLocator(20)
xFormatter = FormatStrFormatter('%d')
yFormatter = FormatStrFormatter('%.2f')
minorLocator   = MultipleLocator(5)


t = arange(0.0, 100.0, 0.1)
s = sin(0.1*pi*t)*exp(-t*0.01)

ax = subplot(111)
plot(t,s)

ax.xaxis.set_major_locator(majorLocator)
ax.xaxis.set_major_formatter(xFormatter)
ax.yaxis.set_major_formatter(yFormatter)

#for the minor ticks, use no labels; default NullFormatter
ax.xaxis.set_minor_locator(minorLocator)

savefig('test.png')