我用大头针将箭头放在正方形的一侧,但是我不能用大头针 (S_2)。
\documentclass[12pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.9}
\usepackage{fouriernc}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
declare function={Y(\x)=\x^3 -6 * \x^2+9*\x;},
axis line style = very thick,
axis lines = center,
xlabel=$x$,ylabel=$y$,
domain=-0.5:5,
ymin=-0.5,
ymax=4.5,
xmin=-1.2,
xmax=4.95,
ytick={4},
samples=100,xtick distance=1,ytick distance=1
,unit vector ratio*=1 1 1,
width=11cm,
grid=major,
grid style={gray!30}]
\addplot [black, thick,name path =A] {Y(x)};
\addplot [black, mark=*,only marks,samples at={0,1,3,4}] {Y(x)};
\node at (axis cs:-0.25, -0.25) {$O$} ;
\addplot [ thick] coordinates {(4, 0) (4, 4) (0,4)};
\addplot[name path =C,domain=0:4] {4};
\addplot[name path =D,domain=0:4] {0};
\addplot[pattern=north east lines, domain=0:1,samples=1000] fill between[of=A and D,soft clip={domain=3:4},];
\addplot[pattern=north east lines, domain=0:1,samples=1000] fill between[of=A and C,soft clip={domain=0:1},];
\begin{scope}[
every pin edge/.style={thick,<-,>=latex},
pin distance=1.5cm
]
\node[pin=60:{$S_2$},] at (axis cs:4.001,1.3) {};
\node[pin=-150:{$S_1$},] at (axis cs:0.1,2) {};
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
我该如何改正它们?
答案1
我怀疑你喜欢实现这样的目标:
为此,您需要制作节点inner sep=0
,或使用以下等效解决方案:
\documentclass[12pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.9}
\usepackage{fouriernc}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
declare function={Y(\x)=\x^3 -6 * \x^2+9*\x;},
axis line style = very thick,
axis lines = center,
xlabel=$x$,ylabel=$y$,
domain=-0.5:5,
ymin=-0.5,
ymax=4.5,
xmin=-1.2,
xmax=4.95,
ytick={4},
samples=100,xtick distance=1,ytick distance=1
,unit vector ratio*=1 1 1,
width=11cm,
grid=major,
grid style={gray!30}]
\addplot [black, thick,name path =A] {Y(x)};
\addplot [black, mark=*,only marks,samples at={0,1,3,4}] {Y(x)};
\node at (axis cs:-0.25, -0.25) {$O$} ;
\addplot [ thick] coordinates {(4, 0) (4, 4) (0,4)};
\addplot[name path =C,domain=0:4] {4};
\addplot[name path =D,domain=0:4] {0};
\addplot[pattern=north east lines, domain=0:1,samples=1000] fill between[of=A and D,soft clip={domain=3:4},];
\addplot[pattern=north east lines, domain=0:1,samples=1000] fill between[of=A and C,soft clip={domain=0:1},];
\begin{scope}[
every pin edge/.style={thick,latex-},
pin distance=1.5cm
]
\node[coordinate,pin= 60:{$S_2$}] at (axis cs:4,1.3) {};
\node[coordinate,pin=-150:{$S_1$}] at (axis cs:0,2) {};
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
笔记:
请考虑升级pgfplots
到最新版本 (1.14),以便更简单地设置坐标。例如,对于具有以下特征的节点pin
:
\node[coordinate,pin= 60:{$S_2$}] at (4,1.3) {};
\node[coordinate,pin=-150:{$S_1$}] at (0,2) {};