I have code to plot the zero contour of a function. This function is symmetric about the x=0 axis, but I only want to display it in the first quadrant. Additionally, I currently set up the axes as a separate plot and combine this contour, and everything else that I want to plot in a Show
command. To limit the plot to the first quadrant I put the plot of the axes first, as shown in the MWE below (I have boiled it down to plotting a quarter of the unit circle):
ClearAll["Global`*"];
axesrng = {0, 1.25}; (* I want to create the axes seperately *)
xrngplot = {0.0, 1.0}; (* plot range for the circle plot *)
xyunitcirc[x_, y_] := x^2 + y^2 - 1;
yunitcirc[x_] := y /. Solve[xyunitcirc[x, y] == 0, y];
axes = Plot[{}, {x, axesrng[[1]], axesrng[[2]]},
PlotRange -> {axesrng, axesrng}, AspectRatio -> 1,
ImageSize -> 100, PlotRangePadding -> 0];
testplot =
Show[axes, Plot[yunitcirc[x], {x, xrngplot[[1]], xrngplot[[2]]}]]
Export[ NotebookDirectory[] <> "testplot.pdf", testplot]
The problem is that Mathematica "secretly" plots the part of the contour that is in the fourth quadrant when I save it in a .pdf file (the same thing happens when I save it as a .svg file). This can be seen when I open it in inkscape - I can access the "hidden" part of the contour using the edit node tool:
Sometimes this extra part is invisible, but sometimes it's not, as shown in the screenshot below which has the real-life plots I made (i.e. more than the MWE I have provided), and was compiled into a LaTeX document using some process I don't know about that reveals the "secret" parts of the plot; you see that the green curve extends down into the lower plot and the orange curve extends too far above and below the axes.
Is there an easy fix to suppress the creation of a graphics vector outside the axes range given by axesrng
?
(Obviously one thing I could do is to convert the contour into a polar plot, and plot it between 0 and pi/4, but I would prefer to keep the code in Cartesians and just suppress the parts I don't need.)
Thanks!
RegionFunction
option help? $\endgroup$ContourPlot[x^2 + y^2 - 1 == 0, {x, 0, 1}, {y, 0, 1}]
$\endgroup$RegionFunction
(as suggested above) that might help within Mathematica. However, I would still suggest not trying to solve this in Mathematica. Clipping masks are very common in vector graphics, and you'll find them in many more places than just constraining the graphics to the plot region. E.g., you'll find a clipping mask on everyText
, every label, etc. If that system messes up clipping masks, it is likely to mess up more ... $\endgroup$