# How can I determine or control a plot's display scale?

Suppose I do something like

p = plot(sin(x), (x,0,2*pi))
p.save("/tmp/plot.png")


Is there some way of knowing (or even better, controlling) exactly the scale of the saved image in pixels per axis unit (in each direction)?

For example, if I wish to write a second graph to a different png file at exactly the same scale, is there some way to do this?

Or, to put it differently, instead of specifying the size of the output png file in inches using figsize, I wish to specify the size in inches (or pixels) per graph unit.

This matplotlib tutorial seems to be about what interests me, but I don't understand how Sage relates to matplotlib, and how I can access the transData field, let alone control its value.

edit retag close merge delete

Sort by » oldest newest most voted

Sage uses matplotlib in the backend to do the job of plotting and saving 2D figures. Therefore, Sage comes bundled with matplotlib. The difference is that in Sage you can input the symbolic functions, and Sage will generate the data points and pass them on to matplotlib.

Now, since Sage contains matplotlib, you can run matplotlib commands directly from Sage. For example, an import like

sage: from matplotlib import pyplot as plt


will make pyplot commands available from Sage, as plt.<command>. So, you can use matplotlib commands directly from within Sage.

Importing matplotlib plots back into Sage Graphics is, unfortunately, not yet implemented. You may follow ticket 5128 for any update on this matter, though I am not quite sure what prevented the ticket from getting merged.

more