在轴环境中使用 Shape 几何库的意外行为

在轴环境中使用 Shape 几何库的意外行为

我想画这个倒三角形。

在此处输入图片描述

为此,我使用了图书馆色调。

\documentclass{standalone}
\standaloneconfig{border=5mm 5mm 5mm 5mm}   %  Left  bottom right top
\usepackage{units}
\usepackage{tikz,pgf,import,pgfplots}
\usetikzlibrary{intersections, shapes.geometric}%
\pgfplotsset{compat=1.3} 
\begin{document}
\centering
\begin{tikzpicture}
    % Coordinate system
    \draw[line width=0.75pt,->] (-40mm,0) -- (15mm,0) node[below] {$X$}  coordinate(x axis);
    \draw[line width=0.75pt,->] (0,-5mm) -- (0,15mm) node[above] {$Z$} coordinate(y axis);
           % sea water level
    \draw[blue,x=1.57ex,y=1ex] (-30mm,0mm) sin (-28mm,2mm) cos (-26mm,0mm) sin (-24mm,-2mm) cos (-22mm,0mm);
    \node[blue,scale=0.5,anchor=south,isosceles triangle, draw, shape border uses incircle, shape border rotate=-90, node font=\itshape, label={above left:SWL}] at (-34mm,0mm) {};
    \draw[blue] (-36mm,-1mm)--(-32mm,-1mm);
    \draw[blue] (-35mm,-2mm)--(-33mm,-2mm);
    \draw[blue] (-34.5mm,-3mm)--(-33.5mm,-3mm);
\end{tikzpicture}
\end{document}

我得到了想要的形状。 在此处输入图片描述

但是,当我添加轴环境来添加正弦波时,同一段代码不再起作用。我在坐标系方面遇到了一些问题。

\documentclass{standalone}
\standaloneconfig{border=5mm 5mm 5mm 5mm}   %  Left  bottom right top
\usepackage{units}
\usepackage{tikz,pgf,import,pgfplots}
\usetikzlibrary{intersections, shapes.geometric}%
\pgfplotsset{compat=1.3} 
\begin{document}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=-5, xmax=5, ymin=-5, ymax=5,
            xtick=\empty, ytick=\empty, axis lines=center]
    %Sine wave
    \addplot[blue, domain=-4:4]  {sin(deg (x))};
    % Ground
     \draw(axis cs: -4,-4.5)--(axis cs: 4,-4.5);
     % sea water level
    \node[blue,scale=0.5,anchor=south,isosceles triangle, draw, shape border uses incircle, shape border rotate=-90, node font=\itshape, label={above left:SWL}] (axis cs: -3cm,0cm) {};
\end{axis}
\end{tikzpicture}
\end{document}

这是我得到的:

在此处输入图片描述

我只得到了半个三角形,并且没有找到坐标的工作方式,因为我无法将它移动到它应该在的位置。

欢迎任何帮助/指导。

亲切的问候!

答案1

我不是 pgfplots 用户。我在 -6 和 -4 之间创建了一个横坐标轴函数域,pos=[0.5] 给出了放置三角形的中间位置。

    \documentclass{standalone}
    %https://tex.stackexchange.com/questions/644949/unspected-behaviour-using-shape-geometric-library-inside-axis-environment
    \standaloneconfig{border=5mm 5mm 5mm 5mm}   %  Left  bottom right top
    \usepackage{tikz,pgfplots}
    \usetikzlibrary{intersections, shapes.geometric}%
    \pgfplotsset{compat=1.3} 
    \begin{document}
    \centering
    \begin{tikzpicture}
    \begin{axis}[xmin=-7, xmax=5, ymin=-5, ymax=5,
                %xtick=\empty,
                ytick=\empty, axis lines=center]
        %Sine wave
        \addplot[blue, domain=-4:4]  {sin(deg (x))};
        \addplot[domain=-6:-4]  {0}
        coordinate [pos=0.5](A);% the middle 
        %sea water level
        \node[blue,scale=0.5,anchor=south,isosceles triangle, draw, shape border uses incircle, shape border rotate=-90, node font=\itshape, label={above left:SWL}] at (A) {};
    \end{axis}
    \end{tikzpicture}
    \end{document}

相关内容