Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

I want to plot a function, say $ f(x) = \frac{1}{x} $, in a certain interval, $ x \in [-2, 2] $, but produce the resulting plot in a broader interval, $ x \in [-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")