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, 05 Aug 2012 02:09:55 +0200Vertical and horizontal span on plotshttps://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/Hello!
Is there a way to add a vertical or horizontal span to a plot in Sage?
I need something similar to *axhspan()* and *axvspan()* functions in Matplotlib ([example](http://matplotlib.sourceforge.net/examples/pylab_examples/axhspan_demo.html)).
Thank you!Fri, 03 Aug 2012 08:11:06 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/Comment by shahuwang for <p>Hello!</p>
<p>Is there a way to add a vertical or horizontal span to a plot in Sage?
I need something similar to <em>axhspan()</em> and <em>axvspan()</em> functions in Matplotlib (<a href="http://matplotlib.sourceforge.net/examples/pylab_examples/axhspan_demo.html">example</a>).</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19288#post-id-19288Actually,Sage's plot module is a wrapper of matplotlib, so you can use Matplotlib directlyFri, 03 Aug 2012 08:16:57 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19288#post-id-19288Comment by v_2e for <p>Hello!</p>
<p>Is there a way to add a vertical or horizontal span to a plot in Sage?
I need something similar to <em>axhspan()</em> and <em>axvspan()</em> functions in Matplotlib (<a href="http://matplotlib.sourceforge.net/examples/pylab_examples/axhspan_demo.html">example</a>).</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19287#post-id-19287Yes, I know I can use Matplotlib directly, but using Sage's *list_plot()* function is very convenient, and I would like to mark some range along the horizontal axis on the plot generated by several consecutive *list_plot()* calls. Currently I just add a coloured polygon, but I have to adjust its edges to exactly fit the area I need. *axvspan()* is much easier to use in this sense.Fri, 03 Aug 2012 10:19:43 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19287#post-id-19287Answer by calc314 for <p>Hello!</p>
<p>Is there a way to add a vertical or horizontal span to a plot in Sage?
I need something similar to <em>axhspan()</em> and <em>axvspan()</em> functions in Matplotlib (<a href="http://matplotlib.sourceforge.net/examples/pylab_examples/axhspan_demo.html">example</a>).</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?answer=13890#post-id-13890I'm not sure I understand exactly what you are doing. But, you can specify the tickmarks using `ticks`.
a=[1,2,3,0.3,0.4]
list_plot(a,ticks=[[0.5,0.7,1],[1,2,3]])
You can specify the min and max of the axis ranges with `xmin, xmax, ymin,ymax`.
a=[1,2,3,0.3,0.4]
list_plot(a,ticks=[[0.5,0.7,1],[1,2,3]],xmax=7)
Does this help?
Fri, 03 Aug 2012 11:59:08 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?answer=13890#post-id-13890Comment by v_2e for <p>I'm not sure I understand exactly what you are doing. But, you can specify the tickmarks using <code>ticks</code>.</p>
<pre><code>a=[1,2,3,0.3,0.4]
list_plot(a,ticks=[[0.5,0.7,1],[1,2,3]])
</code></pre>
<p>You can specify the min and max of the axis ranges with <code>xmin, xmax, ymin,ymax</code>.</p>
<pre><code>a=[1,2,3,0.3,0.4]
list_plot(a,ticks=[[0.5,0.7,1],[1,2,3]],xmax=7)
</code></pre>
<p>Does this help?</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19281#post-id-19281No, marking a range with the axis ticks only is not exactly what I want. What I want is to paint some part of a plot along the X-axis with some color. Just like in the Matplotlib example I gave a link to.Sat, 04 Aug 2012 15:44:10 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19281#post-id-19281Answer by Jason Grout for <p>Hello!</p>
<p>Is there a way to add a vertical or horizontal span to a plot in Sage?
I need something similar to <em>axhspan()</em> and <em>axvspan()</em> functions in Matplotlib (<a href="http://matplotlib.sourceforge.net/examples/pylab_examples/axhspan_demo.html">example</a>).</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?answer=13897#post-id-13897There is not a direct analogue to axhspan or axvspan, though it would probably be fairly straightfoward to wrap those two matplotlib commands (patches welcome!). Alternatively, you could construct the plot you want, then call the `.matplotlib()` method on the plot, and then add whatever you want to the resulting matplotlib figure. Then save the matplotlib figure using the normal matplotlib commands.Sat, 04 Aug 2012 15:11:35 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?answer=13897#post-id-13897Comment by Jason Grout for <p>There is not a direct analogue to axhspan or axvspan, though it would probably be fairly straightfoward to wrap those two matplotlib commands (patches welcome!). Alternatively, you could construct the plot you want, then call the <code>.matplotlib()</code> method on the plot, and then add whatever you want to the resulting matplotlib figure. Then save the matplotlib figure using the normal matplotlib commands.</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19280#post-id-19280See http://www.sagemath.org/doc/reference/sage/plot/graphics.html#sage.plot.graphics.Graphics.matplotlibSun, 05 Aug 2012 02:09:55 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19280#post-id-19280Comment by v_2e for <p>There is not a direct analogue to axhspan or axvspan, though it would probably be fairly straightfoward to wrap those two matplotlib commands (patches welcome!). Alternatively, you could construct the plot you want, then call the <code>.matplotlib()</code> method on the plot, and then add whatever you want to the resulting matplotlib figure. Then save the matplotlib figure using the normal matplotlib commands.</p>
https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19282#post-id-19282Hmm... That sounds interesting promising. I didn't know about such possibility. I'll definitely play with it a bit. Thanks for the tip! :)Sat, 04 Aug 2012 15:42:09 +0200https://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/?comment=19282#post-id-19282