# Plot only those regions where a function's value is positive

I want to plot only those portions of the following function in which the function is positive (e.g. from $0-0.01$ & $0.02-0.03$ and so on):

$$230\sqrt{2}\sin\left(100\pi t\right)$$

In addition to that, I want to create some dotted lines in the plot with values next to it!

How can I do this in one Mathematica expression?

My code so far:

Plot[{230 Sqrt[2] Sin[100 Pi*t]}, {t, 0, 40*10^(-3)}]

• Look up Plot in the help files and try it out. The help files should be your first go-to when learning new software, and Mathematica's are particularly good. Commented Sep 9, 2015 at 16:59
• I've done that, and I can't -> that's why I choose to ask it here Commented Sep 9, 2015 at 17:00
• I'm not sure that I understand what you mean by "positive sides" and why you indicate non-contiguous intervals. You say that you did obtain a plot already: please include the code that worked so far in your question, as a starting point. Commented Sep 9, 2015 at 17:01
• Then it's a good idea to post what you tried. Commented Sep 9, 2015 at 17:02

This might give you something to work on as a start.

Plot[
230 Sqrt[2] Sin[100 Pi t], {t, 0, 0.03},
GridLines -> {{0, 0.01, 0.02}, {-100, 250}},
GridLinesStyle -> {{Dashed, Red}, {Dotted, Blue}},
Epilog -> {
Red, Text[Style[0.01, FontSize -> 18], {0.01, 310}, Background -> White],
Blue, Text[Style[250, FontSize -> 24], {0.025, 250}, Background -> White]
},
ImageSize -> Large
]


I'd suggest that you look up all functions and options used in the code above to familiarize yourself with them and to adapt them to your needs.

You can show only the positive portion of the plot in two ways, either by using a PlotRange option as suggested by george2079, or by specifying a RegionFunction (see docs), with slightly different results.

(* with a RegionFunction *)
Plot[
230 Sqrt[2] Sin[100 Pi t], {t, 0, 0.03},
RegionFunction -> (#2 >= 0 &)
]


(* with PlotRange *)
Plot[230 Sqrt[2] Sin[100 Pi t], {t, 0, 0.03},
PlotRange -> {0, Automatic}
]


As you can see, PlotRange restricts the region of space shown; RegionFunction instead does not alter the plot range, but simply only shows points that conform to the condition specified.

• First of all thanks for your help, but the only thing I dont know is to cut the negative values (in the interval: 0.010 to 0.020) out of the plot? Commented Sep 9, 2015 at 17:23
• PlotRange->{0,Automatic} Commented Sep 9, 2015 at 18:41
• @JanEerland I modified my answer to include your request. Let me know if this is what you were looking for. Commented Sep 9, 2015 at 20:14
• Wow it worked! Thanks a lot! Commented Sep 9, 2015 at 20:24