Ask Your Question

Vertical and horizontal span on plots

asked 2012-08-03 01:11:06 -0500

v_2e gravatar image


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 flag offensive close merge delete


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

shahuwang gravatar imageshahuwang ( 2012-08-03 01:16:57 -0500 )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.

v_2e gravatar imagev_2e ( 2012-08-03 03:19:43 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-08-04 08:11:35 -0500

Jason Grout gravatar image

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.

edit flag offensive delete link 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! :)

v_2e gravatar imagev_2e ( 2012-08-04 08:42:09 -0500 )edit

answered 2012-08-03 04:59:08 -0500

calc314 gravatar image

I'm not sure I understand exactly what you are doing. But, you can specify the tickmarks using ticks.


You can specify the min and max of the axis ranges with xmin, xmax, ymin,ymax.


Does this help?

edit flag offensive delete link 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.

v_2e gravatar imagev_2e ( 2012-08-04 08:44:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-08-03 01:11:06 -0500

Seen: 543 times

Last updated: Aug 04 '12