TeX - LaTeX Asked on June 19, 2021
I have a series of plots that are filled with fill between
. After I produce the plots, I draw a line which goes from the center of the area to an external point. I would like the line to disappear under a certain area. Until now I was able to produce just this
based on the following instructions
documentclass[10pt]{article}
usepackage{amsmath,bm}
usepackage{amssymb}
usepackage{pgfplots}
usepackage{tikz}
usepackage{tikzscale}
usepgfplotslibrary{fillbetween}
begin{document}
begin{tikzpicture}
begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2]
addplot[forget plot,
name path=A,
thick,
color=blue,
] {sin(deg(x))};
addplot[forget plot,
name path=B,
thick,
color=green,
] {2*sin(deg(x))};
addplot[forget plot,
name path=C,
thick,
color=red,
] {3*sin(deg(x))};
addplot[forget plot, name path=axis,domain=0:pi/2]{0};
addplot[red] fill between[of=C and axis];
addplot[green] fill between[of=B and axis];
addplot[blue] fill between[of=A and axis];
addplot [forget plot, mark=none, black] coordinates { (-0.5,0.5) (1,0.5)};
addplot [forget plot, mark=none, black] coordinates { (-0.5,1) (1,1)};
addplot [forget plot, mark=none, black] coordinates { (-0.5,2) (1,2)};
node at (axis cs:-0.5,0.5) [anchor=east] {$sin(x)$};
node at (axis cs:-0.5,1) [anchor=east] {$2*sin(x)$};
node at (axis cs:-0.5,2) [anchor=east] {$3*sin(x)$};
end{axis}
end{tikzpicture}
end{document}
If I understood you comment to question correctly, than you after something like this:
documentclass[border=3.141592]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
pgfplotsset{compat=1.17}
begin{document}
begin{tikzpicture}
begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2,
domain=0:pi/2,
trig format=rad,
]
addplot[name path=A, thick] {sin(x)};
addplot[name path=B, draw=none] {2*sin(x)};
addplot[name path=C, draw=none] {3*sin(x)};
addplot[name path=axis] {0};
addplot[red, semitransparent] fill between[of=C and axis];
addplot[green, semitransparent] fill between[of=B and axis];
addplot[blue, semitransparent] fill between[of=A and axis];
draw (1,0.50) -- (-0.5,0.50) node[left] {$sin(x)$}
(1,1.25) -- (-0.5,1.25) node[left] {$2*sin(x)$}
(1,2.00) -- (-0.5,2.00) node[left] {$3*sin(x)$};
end{axis}
end{tikzpicture}
end{document}
For fill color is used semitransparent
option that curve of function sin(x)
is better visible. In diagram code I also took liberty for make it shorter and simpler.
Addendum (1): You may liked diagram with tick of function domain in shown in radians:
for this diagram you only need to add to axis
option the following code lines:
xtick={0, pi/6, pi/3, pi/2},
xticklabels={0,$pi/6$,$pi/3$,$pi/2$},
xticklabel style = {font=footnotesize},
Addendum (2):
Considering OP comment below this answer, which make problem more clear, the one of possible (general) solution is employ ZikZ library intersections
:
documentclass[border=3.141592]{standalone}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
usetikzlibrary{intersections}
pgfplotsset{compat=1.17}
begin{document}
begin{tikzpicture}
begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2,
xtick={0, pi/6, pi/3, pi/2},
xticklabels={0,$pi/6$,$pi/3$,$pi/2$},
xticklabel style = {font=footnotesize},
domain=0:pi/2,
trig format=rad,
every axis plot post/.append style={draw=none}
]
addplot[name path=A] {sin(x)};
addplot[name path=B] {2*sin(x)};
addplot[name path=C] {3*sin(x)};
addplot[name path=axis] {0};
addplot[red, semitransparent] fill between[of=C and axis];
addplot[green, semitransparent] fill between[of=B and axis];
addplot[blue, semitransparent] fill between[of=A and axis];
path [name path=A1] (-0.5,0.50) node[left] (a) {$sin(x)$} -- (pi/2,0.50);
path [name path=B1] (-0.5,1.25) node[left] (b) {$sin(x)$} -- (pi/2,1.25);
path [name path=C1] (-0.5,2.00) node[left] (c) {$sin(x)$} -- (pi/2,2.00);
draw [name intersections={of=A and A1, by=a1}] (a) -- (a1);
draw [name intersections={of=B and B1, by=b1}] (b) -- (b1);
draw [name intersections={of=C and C1, by=c1}] (c) -- (c1);
end{axis}
end{tikzpicture}
end{document}
Edit: Corrected are errors in naming of x ticks.
Correct answer by Zarko on June 19, 2021
If I have well understood the request, you need to adjust the x coordinate so that it corresponds to a point on the graph. For this we have to use the inverse functions asin(y)
, asin(y/2)
and asin(y/3)
documentclass[10pt]{article}
usepackage{amsmath,bm}
usepackage{amssymb}
usepackage{pgfplots}
usepackage{tikz}
usetikzlibrary{math}
usepackage{tikzscale}
usepgfplotslibrary{fillbetween}
begin{document}
begin{tikzpicture}
begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2]
addplot[forget plot,
name path=A,
thick,
color=blue,
] {sin(deg(x))};
addplot[forget plot,
name path=B,
thick,
color=green,
] {2*sin(deg(x))};
addplot[forget plot,
name path=C,
thick,
color=red,
] {3*sin(deg(x))};
addplot[forget plot, name path=axis,domain=0:pi/2]{0};
addplot[red] fill between[of=C and axis];
addplot[green] fill between[of=B and axis];
addplot[blue] fill between[of=A and axis];
addplot [forget plot, mark=none, black]
coordinates { (-0.5,0.5) (rad(asin(0.5)),0.5)}; % <-----------
addplot [forget plot, mark=none, black]
coordinates { (-0.5,1) (rad(asin(1/2)),1)}; % <-------------
addplot [forget plot, mark=none, black]
coordinates { (-0.5,2) (rad(asin(2/3)),2)};% <-----------------
node at(axis cs:-0.5,0.5)[anchor=east] {$sin(x)$};
node at (axis cs:-0.5,1) [anchor=east]{$2*sin(x)$};
node at (axis cs:-0.5,2) [anchor=east]{$3*sin(x)$};
end{axis}
end{tikzpicture}
end{document}
Answered by Hafid Boukhoulda on June 19, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP