5
$\begingroup$

I am using the option PlotRangePadding -> None to make the curves exactly cut at the specified PlotRange and thus at the frame edges as follow:

plot= With[{XZ = 170, YZ = 230, m = 1.5}, 
  Plot[{-Sqrt[x^2 + 1], Sqrt[x^2 + 1], Sqrt[0.5 x], -Sqrt[0.5 x], 
    Sqrt[-0.5 x], -Sqrt[-0.5 x]}, {x, -2.5, 2.5}, 
   PlotRange -> {-2, 2}, PlotStyle -> Directive[{Red, Thick}], 
   Frame -> True, FrameStyle -> Directive[{Black}], 
   LabelStyle -> {FontFamily -> "Latin Modern Roman", Black, 
     FontSize -> 16}, FrameLabel -> {"x", "y"}, Axes -> False, 
   ImageSize -> Automatic -> {XZ, YZ}, ImagePadding -> 80, 
   PlotRangePadding -> None]]  

and then use Export["C:\\Users\\plot.pdf", plot] to get the figure, but the curves extend to exist outside the frame, see green arrow on the below picture. However, the curves are nicely cut along the right side of the y-axis, see red arrow

enter image description here

$\endgroup$
  • 1
    $\begingroup$ You have conflicting goals. A theoretical line has no thickness, Since some thickness must be added to see or draw it, it is no longer constrained to be within its theoretical limits. You are compounding the problem by making the line Thick. You will need some small PlotRangePadding, e.g., PlotRangePadding -> 0.03. However, then you can have some small gaps at the plot edges. $\endgroup$ – Bob Hanlon Nov 22 at 15:31
  • 1
    $\begingroup$ @Bob Hanlon, then why is the end of the curve along the right y-axis is perfectly aligned with the fram as indicated by the red arrow? $\endgroup$ – HD2006 Nov 22 at 16:24
  • $\begingroup$ Perhaps happenstance? $\endgroup$ – Bob Hanlon Nov 22 at 16:34
  • $\begingroup$ @BobHanlon, I don't think so, I tried a lot of different plots and it is always the case! $\endgroup$ – HD2006 Nov 22 at 16:58
  • $\begingroup$ Try Export["C:\\Users\\plot.pdf", Image@plot]; $\endgroup$ – LouisB Nov 22 at 22:35
4
$\begingroup$

Use PlotStyle -> Directive[{Red, Thick, CapForm["Butt"]}] (CapForm["Mitter"] also works):

plot = With[{XZ = 170, YZ = 230, m = 1.5}, 
  Plot[{-Sqrt[x^2 + 1], Sqrt[x^2 + 1], Sqrt[0.5 x], -Sqrt[0.5 x], 
    Sqrt[-0.5 x], -Sqrt[-0.5 x]}, {x, -2.5, 2.5}, 
   PlotRange -> {-2, 2}, 
   PlotStyle -> Directive[{Red, Thick, CapForm["Butt"]}], 
   Frame -> True, FrameStyle -> Directive[{Black}], 
   LabelStyle -> {FontFamily -> "Latin Modern Roman", Black, 
     FontSize -> 16}, FrameLabel -> {"x", "y"}, Axes -> False, 
   ImageSize -> Automatic -> {XZ, YZ}, ImagePadding -> 80, 
   PlotRangePadding -> None]]

Export["plot.pdf", plot]

enter image description here

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ In 2D graphics, the default is CapForm["Square"]. $\endgroup$ – kglr Nov 22 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.