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.Tue, 22 Oct 2013 20:16:50 +0200Density plot aspect ratiohttps://ask.sagemath.org/question/10642/density-plot-aspect-ratio/I am trying to make a very high aspect ratio density plot, but I can't seem to manually adjust the aspect ratio, and the automatically generated plot ends up being just a very pretty line. What am I doing wrong? The code I'm using is below. I don't know how to use Markdown to make it look pretty, sorry :(
print("Diffusion length data")
k = 1.381E-023
T = 300
q = 1.602E-019
var('ue')
De(ue) = ue*k*T/q
var('tau')
Le = (tau*10^-9*De)^(1/2)
D = density_plot(Le*10^4, (tau, 0, 3), (ue, 0, 500), cmap="jet")
D.show(aspect_ratio=0.05)Mon, 21 Oct 2013 15:23:45 +0200https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/Answer by kcrisman for <p>I am trying to make a very high aspect ratio density plot, but I can't seem to manually adjust the aspect ratio, and the automatically generated plot ends up being just a very pretty line. What am I doing wrong? The code I'm using is below. I don't know how to use Markdown to make it look pretty, sorry :(</p>
<pre><code>print("Diffusion length data")
k = 1.381E-023
T = 300
q = 1.602E-019
var('ue')
De(ue) = ue*k*T/q
var('tau')
Le = (tau*10^-9*De)^(1/2)
D = density_plot(Le*10^4, (tau, 0, 3), (ue, 0, 500), cmap="jet")
D.show(aspect_ratio=0.05)
</code></pre>
https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?answer=15582#post-id-15582This is a bug in how we pass aspect ratio in to plots using matplotlib's `imshow` command, and thank you for finding it; the typical use cases have been square inputs! I've opened [Trac 15315](http://trac.sagemath.org/ticket/15315) for this. I tried to look for a few workarounds, but the things I tried for accessing the aspect ratio of the underlying mpl figure wouldn't propagate (for the cognoscenti, even doing `savefig` now doesn't work in Sage).Mon, 21 Oct 2013 22:36:21 +0200https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?answer=15582#post-id-15582Answer by ppurka for <p>I am trying to make a very high aspect ratio density plot, but I can't seem to manually adjust the aspect ratio, and the automatically generated plot ends up being just a very pretty line. What am I doing wrong? The code I'm using is below. I don't know how to use Markdown to make it look pretty, sorry :(</p>
<pre><code>print("Diffusion length data")
k = 1.381E-023
T = 300
q = 1.602E-019
var('ue')
De(ue) = ue*k*T/q
var('tau')
Le = (tau*10^-9*De)^(1/2)
D = density_plot(Le*10^4, (tau, 0, 3), (ue, 0, 500), cmap="jet")
D.show(aspect_ratio=0.05)
</code></pre>
https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?answer=15581#post-id-15581Thanks for reporting. It is a bug in Sage. Opened ticket 15314 to track this.
*Update*: Proposed fix is in ticket 15315.
Edit by kcrisman - here is what `aspect_ratio=0.01` looks like with the proposed fix.
![image description](/upfiles/1382408651726249.png)Mon, 21 Oct 2013 22:14:28 +0200https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?answer=15581#post-id-15581Comment by wlp2 for <p>Thanks for reporting. It is a bug in Sage. Opened ticket 15314 to track this.</p>
<p><em>Update</em>: Proposed fix is in ticket 15315.</p>
<p>Edit by kcrisman - here is what <code>aspect_ratio=0.01</code> looks like with the proposed fix.</p>
<p><img alt="image description" src="/upfiles/1382408651726249.png"/></p>
https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?comment=16893#post-id-16893This is fantastic! I need to add a contour plot, some data points, and axes labels so I have more work to do. I tried to apply the patch according to the directions in the "Reviewing a patch" section of the developer walkthrough, but got an error that says 'abort: failed to synchronize metadata for "sage/plot/graphics.py"'. Is there another way to apply this patch? Can I edit the source myself without large risk of ruining my sage install? As an end-user this is both a little terrifying and awesome to me at the same time.)Tue, 22 Oct 2013 03:17:59 +0200https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?comment=16893#post-id-16893Comment by ppurka for <p>Thanks for reporting. It is a bug in Sage. Opened ticket 15314 to track this.</p>
<p><em>Update</em>: Proposed fix is in ticket 15315.</p>
<p>Edit by kcrisman - here is what <code>aspect_ratio=0.01</code> looks like with the proposed fix.</p>
<p><img alt="image description" src="/upfiles/1382408651726249.png"/></p>
https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?comment=16892#post-id-16892You can try the following to patch it manually and rebuild sage. I will assume that `SAGE_ROOT` is the directory where your sage is installed, i.e., to run sage you need to actually run `SAGE_ROOT/sage`.
$ cd SAGE_ROOT/devel/sage
$ patch -p1 --dry-run -i /path/to/trac_15315-density_and_matrix_plot_aspect_ratio.patch
$ patch -p1 -i /path/to/trac_15315-density_and_matrix_plot_aspect_ratio.patch # If above had no errors
$ ../../sage -b # rebuild sage
Tue, 22 Oct 2013 04:21:58 +0200https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?comment=16892#post-id-16892Comment by wlp2 for <p>Thanks for reporting. It is a bug in Sage. Opened ticket 15314 to track this.</p>
<p><em>Update</em>: Proposed fix is in ticket 15315.</p>
<p>Edit by kcrisman - here is what <code>aspect_ratio=0.01</code> looks like with the proposed fix.</p>
<p><img alt="image description" src="/upfiles/1382408651726249.png"/></p>
https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?comment=16888#post-id-16888That worked perfectly, thanks ppurka! Also thanks kcrisman, you guys responded very quickly.Tue, 22 Oct 2013 20:16:50 +0200https://ask.sagemath.org/question/10642/density-plot-aspect-ratio/?comment=16888#post-id-16888