Ask Your Question
0

Vertical and horizontal span on plots

asked 2012-08-03 08:11:06 +0200

v_2e gravatar image

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

Comments

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

shahuwang gravatar imageshahuwang ( 2012-08-03 08:16:57 +0200 )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 10:19:43 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-08-04 15:11:35 +0200

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

Comments

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 15:42:09 +0200 )edit
0

answered 2012-08-03 11:59:08 +0200

calc314 gravatar image

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?

edit flag offensive delete link more

Comments

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 15:44:10 +0200 )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

Stats

Asked: 2012-08-03 08:11:06 +0200

Seen: 1,074 times

Last updated: Aug 04 '12