8
$\begingroup$

I want to plot a function over a large range of $x$. The problem is that for very large $x$, even increasing PlotPoint to $5\times10^6$ and MaxRecursion 15, it does not give the whole result. But I can get an accurate result for a short domain.

Then, is it possible to ask Mathematica to stick the plots together to give something like a continuous plot over a large range?

For example, if I have

P1 = Plot[{0, If[Sin[x \[Pi]] >= 0, 1000]}, {x, 0, 10}, 
  PlotStyle -> {Directive[White, CapForm["Butt"], Opacity[-1], 
     Thickness[0]], 
    Directive[Red, CapForm["Butt"], Opacity[1000], Thickness[.04]]}, 
  PlotPoints -> 50, MaxRecursion -> 6, AspectRatio -> 1/40, 
  Axes -> {True, False}, Ticks -> {{0, 5, 10}, {0, 0}}]
P2 = Plot[{0, If[Cos[x \[Pi]] >= 0, 1000]}, {x, 10, 20}, 
  PlotStyle -> {Directive[White, CapForm["Butt"], Opacity[-1], 
     Thickness[0]], 
    Directive[Blue, CapForm["Butt"], Opacity[1000], Thickness[.04]]}, 
  AspectRatio -> 1/40, Axes -> {True, False}, 
  Ticks -> {{10, 15, 20}, {0, 0}}]

which the result is this

enter image description here

then, how to ask Mathematica to stick them as a continuous plot and gives something like this

enter image description here

Is it possible?

$\endgroup$
0

1 Answer 1

15
$\begingroup$
Show[P1, P2, PlotRange -> All, Ticks -> Automatic]

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ +1 That was an easy one :-) $\endgroup$
    – chris
    Nov 9, 2020 at 21:58

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.