The simple command ContourPlot[x == 0, {x, 0, 1}, {y, 0, 1}]
fails to plot the line x==0
. However If I add a small buffer it works ContourPlot[x == 0, {x, -0.001, 1}, {y, 0, 1}]
. I can implement this fudge for now, but I'd rather I could force ContourPlot to behave as I'd naively expect. Many thanks for your help.
-
$\begingroup$ I am using Mathematica 9.0.0.0 on MAC OS X $\endgroup$– TomCommented Jul 2, 2015 at 14:47
-
9$\begingroup$ ContourPlot subdivides the region into smaller and smaller parts to localize the contour. It's a good idea to make sure that any feature you need discovered by ContourPlot should be in the inside of the region, not on the boundary. What is shown in the figure can always be restricted using PlotRange later. Use PlotRange to control what is shown, use the x and y bounds to control what is computed. $\endgroup$– SzabolcsCommented Jul 2, 2015 at 14:51
-
$\begingroup$ Makes sense. Thanks. $\endgroup$– TomCommented Jul 2, 2015 at 14:54
-
$\begingroup$ I do understand that some function are simply not defined outside of the boundary, but for others PlotRange should be a good workaround. $\endgroup$– SzabolcsCommented Jul 2, 2015 at 14:54
-
$\begingroup$ @Szabolcs. Seems to me that 7 upvotes for a comment warrants an official answer. $\endgroup$– marchCommented Jul 2, 2015 at 22:57
1 Answer
ContourPlot subdivides the region into smaller and smaller parts to localize the contour. It's a good idea to make sure that any feature you need discovered by ContourPlot should be in the inside of the region, not on the boundary. What is shown in the figure can always be restricted using PlotRange later. Use PlotRange
to control what is shown, use the x
and y
bounds to control what is computed.
Here's an example:
ContourPlot[x == 0, {x, -1, 2}, {y, -1, 2},
PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> 0.03]
{x, -1, 2}, {y, -1, 2}
is big enough to include all featuresPlotRange -> {{0, 1}, {0, 1}}
crops what is shown to{{0, 1}, {0, 1}}
PlotRangePadding -> 0.03
adds an additional 3% margin inside of the frame. Setting it to0
will cause thex==0
line to coincide with the left part of the frame.
Hope this helps!
I realize this doesn't treat the case when the function is only defined within a certain domain (e.g. has complex values outside of that domain).