Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

How to enforce limits to the x-axis in plots?

asked 8 years ago

Philosophiæ Naturalis gravatar image

I want to plot a function, say f(x)=1x, in a certain interval, x[2,2], but produce the resulting plot in a broader interval, x[3,3], and store it as a graphical file. This case occurs, e.g., when a function is well-defined only in a certain region, but the plot should illustrate a broader region.

Currently, I pass the new x-axis range via show as follows:

p = plot(1/x, (x, -2, 2), ymax = 10, ymin = -10, exclude = [0])
p.show(xmin = -3, xmax = 3)
p.save("plot.svg")

Is it possible to change the x-axis range in a more direct way (without using show)? For instance,

p = plot(1/x, (x, -2, 2), ymax = 10, ymin = -10, exclude = [0])
p.xmin = -3 
p.xmax = 3
p.save("plot.svg")
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 8 years ago

tmonteil gravatar image

GIven a Python/Sage object p, you can get the list of available methods by doing p.<TAB_BUTTON>, so you can see that there is a set_axes_range method. Then, you can see its documentation by doing p.set_axes_range?. In you case, you can do:

sage: p.set_axes_range(xmin=-3, xmax=3)
Preview: (hide)
link
1

answered 8 years ago

Eugene gravatar image

May I ask why you are not satisfied with using xmin and xmax keywords? Note that you can also pass them to save:

p.save("plot2.svg", xmin=-3, xmax=3)
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 2,434 times

Last updated: Apr 07 '16