Write the code to display the exact image shown above.
1
-
$\begingroup$ Sounds like a give-me-the-codez question. And like homework. $\endgroup$ – Henrik Schumacher Feb 23 '20 at 7:40
Add a comment
|
$\begingroup$
$\endgroup$
I would do it this way.
Show[
Plot[{1/x}, {x, 0, 26},
PlotRange -> {Automatic, {0, .6}},
PlotStyle -> AbsoluteThickness[3]],
Plot[{1/x}, {x, 2, 6},
PlotRange -> {Automatic, {0, .6}},
PlotStyle -> Transparent,
Filling -> Axis,
FillingStyle -> Red],
Plot[1/x, {x, 8, 24},
PlotRange -> {Automatic, {0, .6}},
PlotStyle -> Transparent,
Filling -> Axis,
FillingStyle -> Blue],
Ticks -> {{2, 6, 8, 24}, Automatic}]
$\begingroup$
$\endgroup$
3
A simple answer:
Show[Plot[{1/x, If[2 <= x <= 6, 0, 1/x]}, {x, 0, 26},
Filling -> {1 -> {2}}, AxesOrigin -> {0, 0}, FillingStyle -> {Red},
PlotRange -> {0, 0.6}, PlotStyle -> Black],
Plot[{1/x, If[8 <= x <= 24, 0, 1/x]}, {x, 0, 26},
Filling -> {1 -> {2}}, AxesOrigin -> {0, 0}, FillingStyle -> {Blue},
PlotStyle -> Black], Ticks -> {{2, 6, 8, 24}, Automatic}]
-
1$\begingroup$ I don't think this produces the exact image requested. $\endgroup$ – m_goldberg Feb 23 '20 at 3:31
-
1$\begingroup$ Thanks, It actually works, goldbergs code for some reason does not display. $\endgroup$ – vicsonsam Feb 23 '20 at 6:28
-
1$\begingroup$ @vicsonsam, code by m_goldberg works fine, I edited small typo in there, $\endgroup$ – Alx Feb 23 '20 at 11:30