绘制带有标签的变化波形

绘制带有标签的变化波形

我正在尝试使用 tikzpicture 绘制以下图表。我不知道这个函数图是什么,因为所有时间段都在变化。我如何在 latex 中绘制这个图表?

在此处输入图片描述

编辑:我可以绘制图表。现在我正尝试添加执行标签。这是我编写的代码:

    \documentclass[tikz,border=5]{standalone}
   \usepackage{pgfplots}
   \pgfplotsset{width=10cm,height=6cm,compat=1.18}
   \usetikzlibrary{positioning,arrows}
   \begin{document}     
   \begin{tikzpicture}[x=1.5cm,y=1.5cm]
    \draw[->] (0,0) -- (9,0) node[below] {\textbf{Time}};
    \draw[->] (0,0) -- (0,2.5) node[left] {\textbf{Energy}};
    
    % Draw axes with no labels or numbers
    %\draw[->] (0,0) -- (9,0);
    %\draw[->] (0,0) -- (0,1.5);
    
    % Draw intermittent energy system
    \draw[thick] (0,0.5) to[bend left] (1,2) -- (2,0.5) to[bend left] (3,2) -- (4,0.5) to[bend left] (4.5,2) -- (5.5,0.5) to[bend left] (6.5,2) -- (7.5,0.5) ;
    
    % Draw dashed lines for zero crossing
    \draw[dashed] (0,0) -- (9,0);
    
    % Label turn-off and turn-on thresholds
    \draw[dashed] (0,0.5) -- (8.6,0.5) node[pos=0.6, below] {\textbf{Turn-off threshold}};
    \draw[dashed] (0,2) -- (8.6,2) node[pos=0.6, above] {\textbf{Turn-on threshold}};
    % Draw y-axis ticks from 0 to 1
    %\foreach \y in {0,0.2,...,1}
    %\draw (0.1,\y) -- (0.1,\y);
    \end{tikzpicture}    
    \end{document}

答案1

这种方法使用\pic来绘制曲线的每一部分,包括青色矩形、左侧“图钉”和时间标签(如果有)。它还会创建一些坐标。

\tikzset
{%
   pics/wave/.style n args={4}{% #1 = x (maximun), #2 = y (maximum), #3 = x (end point) #4 = label
     code={%
       \pgfmathsetmacro\myangle{atan{#2/#1}}
       \pgfmathsetmacro\pinwd{0.04}
       \coordinate (-max) at (#1,#2);
       \coordinate (-end) at (#1+#3,0);
       \coordinate (-pin) at (#1-0.075,0.85*#2);
       % rectangle
       \fill[pic actions,draw=none] (-max) rectangle (-end);
       % pin
       \fill[pic actions,draw=none,even odd rule]
            (-pin) ++ (-0.075,-0.075)             rectangle ++ (0.15,0.15)
            (-pin) ++ (-0.075+\pinwd,-0.075+\pinwd) rectangle ++ (0.15-2*\pinwd,0.15-2*\pinwd);
       % label
       \ifblank{#4}{}
       {
         \draw[gray!75!black,|-|,loosely dashed,shorten <=0.025cm,shorten >=0.025cm] (0,0.15*#2) --++ (#1,0) node[midway,above] {#4};
       }
       % curve
       \draw[pic actions,fill=none] (0,0) to[out=0.5*\myangle+45,in=180+0.5*\myangle] (-max) -- (-end);
     }},
   curve/.style={thick,fill=cyan!70}
}

\begin{document}

\begin{tikzpicture}[font=\sffamily\small,line cap=round,line join=round]
%\draw[gray!30] (0,0) grid[step=0.5] (8,3);
% axes
\draw[latex-latex,very thick] (8,0) -- (0,0) node[midway,below] {\bfseries Time} --
                           (0,3) node[midway,sloped,yshift=3mm] {\bfseries Stored Energy};
% curve
\pic[curve] (1) at (0,0.4) {wave={1.5}{1.9}{0.3}{}};
\pic[curve] (2) at (1-end) {wave={2}{1.9}{0.3}{$t_1$}};
\pic[curve] (3) at (2-end) {wave={1}{1.9}{0.3}{$t_2$}};
\pic[curve] (4) at (3-end) {wave={1.7}{1.9}{0.3}{$t_3$}};
% dashed lines
\draw[thick,dashed,orange!70!black] (0,0.4) --++ (8,0);
\draw[thick,dashed,teal!70]         (0,2.3) --++ (8,0);
% labels
\node[cyan]       (Ex) at (2.7,2.5) {Execution};
\node[teal]            at (5.2,2.5) {Turn \textbf{on} Threshold};
\node[orange!70!black] at (5.2,0.2) {Turn \textbf{off} Threshold};
\draw[cyan] (Ex.west) --++ (-1,0) |- (1-pin);
\draw[cyan] (Ex.340)  |-  (4-pin);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容