# 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).

Thank you!

edit retag close merge delete

Actually,Sage's plot module is a wrapper of matplotlib, so you can use Matplotlib directly

( 2012-08-03 08:16:57 +0100 )edit

Yes, 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.

( 2012-08-03 10:19:43 +0100 )edit

Sort by ยป oldest newest most voted

I'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?

more

No, 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.

( 2012-08-04 15:44:10 +0100 )edit

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 .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.

more

Hmm... That sounds interesting promising. I didn't know about such possibility. I'll definitely play with it a bit. Thanks for the tip! :)

( 2012-08-04 15:42:09 +0100 )edit
( 2012-08-05 02:09:55 +0100 )edit