ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Nov 2013 22:13:31 +0100How can I determine or control a plot's display scale?https://ask.sagemath.org/question/10722/how-can-i-determine-or-control-a-plots-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](http://matplotlib.org/users/transforms_tutorial.html) 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.Sun, 10 Nov 2013 19:19:13 +0100https://ask.sagemath.org/question/10722/how-can-i-determine-or-control-a-plots-display-scale/Answer by ppurka for <p>Suppose I do something like</p>
<pre><code>p = plot(sin(x), (x,0,2*pi))
p.save("/tmp/plot.png")
</code></pre>
<p>Is there some way of knowing (or even better, controlling) <em>exactly</em> the scale of the saved image in pixels per axis unit (in each direction)?</p>
<p>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?</p>
<p>Or, to put it differently, instead of specifying the size of the output png file in inches using <code>figsize</code>, I wish to specify the size in inches (or pixels) <em>per graph unit</em>.</p>
<p><a href="http://matplotlib.org/users/transforms_tutorial.html">This matplotlib tutorial</a> seems to be about what interests me, but I don't understand how Sage relates to matplotlib, and how I can access the <code>transData</code> field, let alone control its value.</p>
https://ask.sagemath.org/question/10722/how-can-i-determine-or-control-a-plots-display-scale/?answer=15684#post-id-15684Sage 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.Sun, 10 Nov 2013 22:13:31 +0100https://ask.sagemath.org/question/10722/how-can-i-determine-or-control-a-plots-display-scale/?answer=15684#post-id-15684