我试图重现这个数字:
为此,我已经到达了代码的这一部分:
我遇到了一些问题,因为:
- 我不知道如何实现轴下方的两个灰色矩形。
- 一旦矩形实现:我如何用青色图案填充这些矩形之间的区域?因为在我的代码中,我刚刚构建了一个高斯函数并填充了它下面的区域。因此:我认为不可能以相同的方式填充矩形之间的“间隙”区域。
- 此外(这有点随意),但如果可能的话,学习如何绘制这个“相机”图形对我来说会很好。
\documentclass{article}
\usepackage{amsmath}
\usepackage{accents} % for bar under character
%%%%%% PGFPLOTS %%%%%%%%%%%%
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfmathdeclarefunction{gaussian}{2}
{%
\pgfmathparse{(1/(#1 * sqrt(2 * pi))) * exp((-1 / 2) * (((x - #2)/#1) ^ 2))}%
}
\pgfmathsetmacro{\mean}{7}
\pgfmathsetmacro{\std}{0.3}
\usepackage{enumitem}
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
patterns.meta
}
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:14, samples=200,
axis lines*=left, xlabel=$x$, ylabel=$y$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=17cm,
xtick={\mean,12.5}, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]
\addplot [fill=cyan!20, draw=none, domain=0:14] {gaussian(1.5+\std,\mean)} \closedcycle;
\addplot [name path=haute,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05};
\addplot [name path=basse,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)};
\addplot [very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05}--(14,0); % ligne entre fin de la fonction et axe des abscisses
\addplot fill between[
of = haute and basse,
soft clip={domain=0:14},
every even segment/.style = {pink,opacity=.2}
];
\draw[very thick, cyan!50!black] (0,0) -- (0,0.05011524462);
\draw[dashed,red, stealth-stealth, very thick] (8,0) -- node[fill=cyan!20,scale=0.75] {$h(x,t)$} (8,0.189940);
\draw[dashed,red, stealth-stealth, thick] (7,0.025) -- node[fill=cyan!20,scale=0.75] {$R(x,t)$} (12.5,0.025);
\draw [yshift=-0.6cm, -stealth](7,-0.1) -- node [fill=white] {$Q(t)$} (7,0);
\draw[black, stealth-, very thick] (9,0.13) -- node[right,below right,scale=0.75] {Elastic membrane} (12,0.25);
\draw[black, stealth-, very thick] (6,0.03) -- node[pos = 0.8,below left,scale=0.75] {Silicon oil} (3,0.25);
%\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$Q(t)$} (axis cs:5.96,0);
\end{axis}
\end{tikzpicture}
编辑 :
当我添加以下几行时:
\draw[black, fill=cyan!20] (6.25,-0.1) -- (6.25,0) -- (7.75,0) -- (7.75,-0.1) -- (6.25,-0.1);
\draw[black, fill=gray!20] (0,-0.075) -- (0,0) -- (6.25,0) -- (6.25,-0.075) -- (0,-0.075);
\draw[black, fill=gray!20] (14,-0.075) -- (14,0) -- (7.75,0) -- (7.75,-0.075) -- (14,-0.075);
我最终得到这样的配置:
我怎样才能避免那个填充区域覆盖箭头?
答案1
这就是为什么最好在轴环境之外添加常规 TikZ 命令的原因。
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{accents} % for bar under character
%%%%%% PGFPLOTS %%%%%%%%%%%%
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfmathdeclarefunction{gaussian}{2}
{%
\pgfmathparse{(1/(#1 * sqrt(2 * pi))) * exp((-1 / 2) * (((x - #2)/#1) ^ 2))}%
}
\pgfmathsetmacro{\mean}{7}
\pgfmathsetmacro{\std}{0.3}
\usepackage{enumitem}
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
patterns.meta
}
\begin{document}
\begin{tikzpicture}
\draw[black, fill=cyan!20] (242.85564pt,-0.04128pt) rectangle (195.85132pt,-35.86281pt);
\begin{axis}[
no markers, domain=0:14, samples=200,
axis lines*=left, xlabel=$x$, ylabel=$y$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=17cm,
xtick={\mean,12.5}, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]
\addplot [fill=cyan!20, draw=none, domain=0:14] {gaussian(1.5+\std,\mean)} \closedcycle;
\addplot [name path=haute,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05};
\addplot [name path=basse,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)};
\addplot [very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05}--(14,0); % ligne entre fin de la fonction et axe des abscisses
\addplot fill between[
of = haute and basse,
soft clip={domain=0:14},
every even segment/.style = {pink,opacity=.2}
];
\draw[very thick, cyan!50!black] (0,0) -- (0,0.05011524462);
\draw[dashed,red, stealth-stealth, very thick] (8,0) -- node[fill=cyan!20,scale=0.75] {$h(x,t)$} (8,0.189940);
\draw[dashed,red, stealth-stealth, thick] (7,0.025) -- node[fill=cyan!20,scale=0.75] {$R(x,t)$} (12.5,0.025);
\draw [yshift=-0.6cm, -stealth](7,-0.1) -- node [fill=white] {$Q(t)$} (7,0);
\draw[black, stealth-, very thick] (9,0.13) -- node[right,below right,scale=0.75] {Elastic membrane} (12,0.25);
\draw[black, stealth-, very thick] (6,0.03) -- node[pos = 0.8,below left,scale=0.75] {Silicon oil} (3,0.25);
%\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$Q(t)$} (axis cs:5.96,0);
%%%%% remove from final version
\coordinate (A) at (axis cs: 6.25,-0.1);
\coordinate (B) at (axis cs: 7.75,0);
%%%%%
\draw[black, fill=gray!20] (0,-0.075) rectangle (6.25,0);
\draw[black, fill=gray!20] (14,-0.075) rectangle (7.75,0);
\end{axis}
%%%%% remove from final version
\path(A);
\pgfgetlastxy{\xx}{\yy}
\node[above] at (current bounding box.north) {(\xx,\yy)};
\path(B);
\pgfgetlastxy{\xx}{\yy}
\node[above] at (current bounding box.north) {(\xx,\yy)};
\end{tikzpicture}
\end{document}