3
$\begingroup$

I have an issue with FrameTicks when combined with a plot using Filling. I've plotted two curves (in one Plot[]) with two different colors and I'm trying to use the left and right columns of the frame to separate the data, to look like this:

However, when I use FrameTicks to add the left column's ticks, there is a little gap in the middle of the filling of the plots:

I don't understand the source of the problem, but it has to be linked to the FrameTicks function, because when I delete that part of the code, the gap disappears. Also, the function that I defined was using Piecewise, maybe there is something related. The code is

h = 4.9; (* m *)
g = 9.8; (* m/s^2 *)
m = 1; (* kg *)

Ekin[t_] := Piecewise[{{(m g^2 t^2)/2, 0 ≤ t ≤ Sqrt[(2 h)/g]}, 
                       {(m g^2 (t - 1)^2)/2 + m g (h - (t - 1) Sqrt[2 g h]), t > Sqrt[(2h)/g]}}]
Epot[t_] := Piecewise[{{m g (h - (g t^2)/2), 0 ≤ t ≤ Sqrt[(2 h)/g]}, 
                       {m g ((t - 1) Sqrt[2 g h] - (g (t - 1)^2)/2), t > Sqrt[(2 h)/g]}}]
Energy = Plot[{Ekin[t], Epot[t]}, {t, 0, 2 Sqrt[(2 h)/g]}, 
  PlotStyle -> {{Thickness[0.004], Darker[Blue]}, {Thickness[0.004], Orange}}, 
  PlotRange -> All, Filling -> Axis, Frame -> True, 
  FrameStyle -> {{Directive[Darker[Blue], Thick, 30], Directive[Orange, Thick, 30]},
                 {Directive[Black, Thick, 30], Directive[Black, Thick, 30]}},
  FrameLabel -> {{Style[Row[{Subscript["E", "kin"] , " (J)"}], 50], 
                  Style[Row[{Subscript["E", "pot"] , " (J)"}]]}, {Style["t (s)", 50], None}},
  FrameTicks -> {{All, All}, {All, None}},
  ImageSize -> {1080,720} ]

Well, I changed the fontsize of the left label from 50 to 49 and this practically solves the problem. But then, the question is, why is happening this?

$\endgroup$

1 Answer 1

3
$\begingroup$

Try adding Exclusions -> None as an option to the Plot command.

Mathematica probably detects the discontinuity in the derivative at 0 and plots in two pieces for negative and positive values. The two pieces may not line up perfectly due to rounding to integer pixel values during rendering: there may be either a gap or an overlap. Turning off exclusion detection normally makes the peak be less sharp, but because of the symmetry of this specific plot, you will have a plot point right at the peak anyway.

$\endgroup$
1
  • $\begingroup$ It works! Thanks for the answer. $\endgroup$
    – Verktaj
    Mar 20, 2020 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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