Results 1 to 6 of 6

Math Help - Mathematica - 2D Discontinuous plotting

  1. #1
    Senior Member bkarpuz's Avatar
    Joined
    Sep 2008
    From
    R
    Posts
    481
    Thanks
    2

    Thumbs up Mathematica - 2D Discontinuous plotting

    Dear MHF members,

    I need to plot a figure as in the following figure.
    Mathematica - 2D Discontinuous plotting-ex1.jpg

    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.
    Mathematica - 2D Discontinuous plotting-ex2.jpg

    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
    Last edited by bkarpuz; July 30th 2011 at 12:29 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    May 2010
    Posts
    1,028
    Thanks
    28

    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];
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Senior Member bkarpuz's Avatar
    Joined
    Sep 2008
    From
    R
    Posts
    481
    Thanks
    2

    Re: Mathematica - 2D Discontinuous plotting

    Quote Originally Posted by SpringFan25 View Post
    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]
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    May 2010
    Posts
    1,028
    Thanks
    28

    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
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Aug 2009
    Posts
    29

    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.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Senior Member bkarpuz's Avatar
    Joined
    Sep 2008
    From
    R
    Posts
    481
    Thanks
    2

    Re: Mathematica - 2D Discontinuous plotting

    Quote Originally Posted by Zarathustra View Post
    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Mathematica 8 plotting function 1/x bug??
    Posted in the Math Software Forum
    Replies: 3
    Last Post: May 9th 2011, 11:40 AM
  2. Plotting a function with wolfram mathematica
    Posted in the Math Software Forum
    Replies: 2
    Last Post: March 11th 2010, 06:53 AM
  3. Plotting Asymptotes in Mathematica
    Posted in the Math Software Forum
    Replies: 1
    Last Post: July 5th 2009, 02:44 AM
  4. Replies: 2
    Last Post: June 25th 2009, 10:11 AM
  5. Mathematica Double Sequence Plotting in 3D
    Posted in the Math Software Forum
    Replies: 12
    Last Post: September 13th 2008, 10:55 AM

Search Tags


/mathhelpforum @mathhelpforum