# Thread: Mathematica - 2D Discontinuous plotting

1. ## Mathematica - 2D Discontinuous plotting

Dear MHF members,

I need to plot a figure as in the following figure.

I use the code
Code:
Plot[{t, t - 2 \[Pi]}, {t, 0, 8 \[Pi]}, PlotStyle -> {Red, Blue},
Ticks -> {Table[j \[Pi], {j, 0, 8}], Table[j \[Pi], {j, -2,  8}]}]
to get the following image.

But I don't know how to remove the segments $(\pi,2\pi)$, $(3\pi,4\pi)$, $(5\pi,6\pi)$ and $(7\pi,8\pi)$ from the $x$-axis and remove the same parts of the functions $t$ and $t-2\pi$.

Thanks.
bkarpuz

2. ## Re: Mathematica - 2D Discontinuous plotting

Google suggests something like this might work:

Code:
p1 := Plot[ 2x , {x, -1, 1}];
p2 := Plot[2x, {x, 5, 10}];
Show[p1, p2];

3. ## Re: Mathematica - 2D Discontinuous plotting

Originally Posted by SpringFan25
Google suggests something like this might work:

Code:
p1 := Plot[ 2x , {x, -1, 1}];
p2 := Plot[2x, {x, 5, 10}];
Show[p1, p2];
Thanks SpringFan25.

The following works for me.
But still don't know how to remove the intervals from the $x$-axis.

Code:
Show[Table[{Plot[t, {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> Red],
Plot[t-2 \[Pi], {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> Blue],
Plot[0, {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> {Black, Thick}]}, {j, 0, 3}],
Ticks -> {Table[j \[Pi], {j, 0, 7}], Table[j \[Pi], {j, -2, 7}]},
PlotRange -> All]

4. ## Re: Mathematica - 2D Discontinuous plotting

this might be useful, it show code doing what you want. I ahve no idea how it works though!

http://www.st-andrews.ac.uk/~pl10/c/djmpark/Assets/C3527823/BrokenAxisGraph.pdf

5. ## Re: Mathematica - 2D Discontinuous plotting

Well, a really cheesy way to get the desired output would be something like this:
Code:
Show[Table[{Plot[t, {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> Red],
Plot[t - 2 \[Pi], {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> Blue],
Plot[0, {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> {Black}]}, {j, 0, 3}],
Ticks -> {Table[j \[Pi], {j, 0, 7}], Table[j \[Pi], {j, -2, 7}]},
PlotRange -> {{0, 7 \[Pi]}, {-2 \[Pi], 7 \[Pi]}}, AspectRatio -> 7/9,
Epilog ->
Inset[Show[
Table[Plot[0, {x, j \[Pi], j \[Pi] + \[Pi]},
PlotRange -> {{0, 7 \[Pi]}, {-2 \[Pi], 7 \[Pi]}}, Axes -> False,
PlotStyle -> {{Thickness[.006], White, EdgeForm[]}},
AspectRatio -> 7/9], {j, 1, 7, 2}]], {0, 0}, {0, 0}, {7 \[Pi],
Automatic}]
]
I.e., draw white lines over the parts of the axis you don't want. If you use it to produce a vector graphic to include elsewhere, this might be a problem, though.

Perhaps you could try to play around with the Inset[] function; I have a feeling that it should be possible to create a table of plots for each interval, and then add them to a plot with not axes using Inset. The positioning might be a bit tricky, and you might have to pay attention to AspectRatio.

6. ## Re: Mathematica - 2D Discontinuous plotting

Originally Posted by Zarathustra
Well, a really cheesy way to get the desired output would be something like this:
Code:
Show[Table[{Plot[t, {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> Red],
Plot[t - 2 \[Pi], {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> Blue],
Plot[0, {t, 2 j \[Pi], (2 j + 1) \[Pi]},
PlotStyle -> {Black}]}, {j, 0, 3}],
Ticks -> {Table[j \[Pi], {j, 0, 7}], Table[j \[Pi], {j, -2, 7}]},
PlotRange -> {{0, 7 \[Pi]}, {-2 \[Pi], 7 \[Pi]}}, AspectRatio -> 7/9,
Epilog ->
Inset[Show[
Table[Plot[0, {x, j \[Pi], j \[Pi] + \[Pi]},
PlotRange -> {{0, 7 \[Pi]}, {-2 \[Pi], 7 \[Pi]}}, Axes -> False,
PlotStyle -> {{Thickness[.006], White, EdgeForm[]}},
AspectRatio -> 7/9], {j, 1, 7, 2}]], {0, 0}, {0, 0}, {7 \[Pi],
Automatic}]
]
I.e., draw white lines over the parts of the axis you don't want. If you use it to produce a vector graphic to include elsewhere, this might be a problem, though.

Perhaps you could try to play around with the Inset[] function; I have a feeling that it should be possible to create a table of plots for each interval, and then add them to a plot with not axes using Inset. The positioning might be a bit tricky, and you might have to pay attention to AspectRatio.
Actually, this is what I was looking for. I really appreciate your help Zarathustra. I will read and try to understand it. Many many thanks.
bkarpuz