如何让 Tikz 图钉在点击后显示

如何让 Tikz 图钉在点击后显示
\documentclass[xcolor={table},t]{beamer}    

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
        

\usetikzlibrary{decorations.pathreplacing,angles,quotes,calligraphy,plotmarks,overlay-beamer-styles}

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\begin{document}

\begin{frame}{Test}
    
\begin{figure}

\begin{center}

\begin{tikzpicture}


\begin{axis}[
legend style={at={(1.3,0)},draw=none,anchor= south, legend columns=1, font=\tiny,text width=1in, minimum height=0.2in}, 
ymin=0,ymax=1000,
xlabel = Strain ($\epsilon_{e}$ and $\epsilon_{t}$),
every axis x label/.style=
    {at={(ticklabel cs:0.5)},anchor=near ticklabel},
ylabel = Stress ($F_{t}$ and $F_{e}$),
every axis y label/.style=
    {at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},    
xmin=0, xmax=0.4,
xtick={0,0.05,...,0.4},,
x tick label style={rotate=45},
width=0.75\linewidth,
height=0.58\linewidth,
font=\tiny,    
axis x line=bottom,
axis y line=left,
]
\begin{scope}[
  every pin edge/.style={<-,>=latex, mark size=3pt},
  every pin/.append style={font=\tiny}
]



\addplot [black,mark = *,mark size=3pt,mark options={fill=black}, only marks] coordinates {(0.012,439) (0.182322,614.4) (0.2,512) (0.29,350)};

    \node [coordinate,pin={[visible on=<2->,pin distance=0.35 in,pin edge={gray,thick}]90:{(5) $F_{t}=F_{ut}*[w*\frac{\epsilon_{t}}{\epsilon_{ut}}^n+(1-w)*(1+\epsilon_{t}-\epsilon_{ut})]$} } ]
        at (axis cs:0.239017,638.115116) {};
      
    \node[coordinate,pin={[pin distance=0.25 in,pin edge={gray,thick}]90:{(4) $F_{t}=F_{ut}*(\frac{\epsilon_{t}}{\epsilon_{ut}})^n$} } ]
        at (axis cs:0.095,565) {};            

\node[inner sep=0pt] (whitehead) at (axis cs:0.03,400)
{\tiny{A}};

\node[inner sep=0pt] (whitehead) at (axis cs:0.18,450)
{\tiny{B}};

%\node[inner sep=0pt] (whitehead) at (axis cs:0.33,350)
%{\tiny{C}};

\node[inner sep=0pt] (whitehead) at (axis cs:0.182322,680)
{\tiny{B'}};    

\node[inner sep=0pt] (whitehead) at (axis cs:0.1,160)
{\tiny{Hardening Region}};    

\addplot [<->, black, dashed, thick] coordinates {(0.012,439)  (0.012,0)};
\addplot [<->, black,dashed, thick] coordinates {(0.2,512)  (0.2,0)};
\addplot [<->, black, thick] coordinates {(0.012,100)  (0.2,100)};

\addplot [<->, black, dashed, thick] coordinates {(0.29,350)  (0.29,0)};
\addplot [<->, black, thick] coordinates {(0.2,100)  (0.29,100)};

\node[inner sep=0pt] (whitehead) at (axis cs:0.245,160)
{\tiny{Necking}};    

    %\node[inner sep=0pt] (whitehead) at (axis cs:0.245,180)
%{\tiny$\begin{aligned} Necking, and \\ Fracture \end{aligned}$};    

\node[inner sep=0pt] (whitehead) at (axis cs:0.31,350)
{\tiny{C}}; 

\end{scope}
\end{axis}
\end{tikzpicture}
\end{center}
\caption{True Stress Strain Match}
\label{Tension_Test}
\end{figure}
\end{frame}
\end{document}

答案1

TikZ 节点具有叠加感知功能。这意味着你可以延迟整个节点,包括文本和图钉,\node<2->

关于你的代码的一些其他评论

  • 图形在 beamer 中默认居中。无需在中心环境中扭曲它们。这只会弄乱垂直间距

  • 你不需要visible on自己定义样式,这就是你加载overlay-beamer-styles库的目的

  • frame缺少环境。这是 beamer 的关键部分。切勿在没有框架的情况下使用 beamer !


\documentclass[xcolor={table},t]{beamer}    

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
        

    \usetikzlibrary{decorations.pathreplacing,angles,quotes,calligraphy,plotmarks,overlay-beamer-styles}


\begin{document}
\begin{frame}
\begin{figure}

%\begin{center}

\begin{tikzpicture}


\begin{axis}[
    %x label style={at=(.50,-0.1)},
    %x label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
    %y label style={at={(current axis.above origin)},anchor=west},
    legend style={at={(1.3,0)},draw=none,anchor= south, legend columns=1, font=\tiny,text width=1in, minimum height=0.2in}, 
    ymin=0,ymax=1000,
    xlabel = Strain ($\epsilon_{e}$ and $\epsilon_{t}$),
    every axis x label/.style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    ylabel = Stress ($F_{t}$ and $F_{e}$),
    every axis y label/.style=
        {at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},    
    xmin=0, xmax=0.4,
    xtick={0,0.05,...,0.4},,
    x tick label style={rotate=45},
    width=0.75\linewidth,
    height=0.58\linewidth,
    font=\tiny,    
    axis x line=bottom,
    axis y line=left,
]
\begin{scope}[
      every pin edge/.style={<-,>=latex, mark size=3pt},
      every pin/.append style={font=\tiny}
    ]


        \node<2-> [coordinate,pin={[pin distance=0.35 in,pin edge={gray,thick}]90:{(5) $F_{t}=F_{ut}*[w*\frac{\epsilon_{t}}{\epsilon_{ut}}^n+(1-w)*(1+\epsilon_{t}-\epsilon_{ut})]$} } ] at (axis cs:0.239017,638.115116) {};
          
  
\end{scope}
\end{axis}
\end{tikzpicture}
%\end{center}
\caption{True Stress Strain Match}
\label{Tension_Test}
\end{figure}
\end{frame}
\end{document}

在此处输入图片描述

答案2

我已经解决了这个问题:

visible on=<2->只需简单地添加到引脚选项中,如下所示:

    \node [coordinate,pin={[visible on=<2->,pin distance=0.35 in,pin edge={visible on=<2->,gray,thick}]90:{(5) $F_{t}=F_{ut}*[w*\frac{\epsilon_{t}}{\epsilon_{ut}}^n+(1-w)*(1+\epsilon_{t}-\epsilon_{ut})]$} } ]
        at (axis cs:0.239017,638.115116) {};

完整代码:

\documentclass[xcolor={table},t]{beamer}    

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
        

\usetikzlibrary{decorations.pathreplacing,angles,quotes,calligraphy,plotmarks,overlay-beamer-styles}

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\begin{document}

\begin{frame}{Test}
    
\begin{figure}

\begin{center}

\begin{tikzpicture}


\begin{axis}[
    legend style={at={(1.3,0)},draw=none,anchor= south, legend columns=1, font=\tiny,text width=1in, minimum height=0.2in}, 
    ymin=0,ymax=1000,
    xlabel = Strain ($\epsilon_{e}$ and $\epsilon_{t}$),
    every axis x label/.style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    ylabel = Stress ($F_{t}$ and $F_{e}$),
    every axis y label/.style=
        {at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},    
    xmin=0, xmax=0.4,
    xtick={0,0.05,...,0.4},,
x tick label style={rotate=45},
width=0.75\linewidth,
height=0.58\linewidth,
font=\tiny,    
axis x line=bottom,
axis y line=left,
]
\begin{scope}[
      every pin edge/.style={<-,>=latex, mark size=3pt},
      every pin/.append style={font=\tiny}
    ]

  
\addplot [black,mark = *,mark size=3pt,mark options={fill=black}, only marks] coordinates {(0.012,439) (0.182322,614.4) (0.2,512) (0.29,350)};

    
%\node[inner sep=0pt] (whitehead) at (axis cs:0.5,250)
    %{\tiny{(1) $\sigma_T=\ln*(1+\epsilon_{eng})$}};    
    
    
    %\node[inner sep=0pt] (whitehead) at (axis cs:0.12,650)
    %{\tiny{Eq. (1), (2)}};

        \node [coordinate,pin={[visible on=<2->,pin distance=0.35 in,pin edge={visible on=<2->,gray,thick}]90:{(5) $F_{t}=F_{ut}*[w*\frac{\epsilon_{t}}{\epsilon_{ut}}^n+(1-w)*(1+\epsilon_{t}-\epsilon_{ut})]$} } ]
            at (axis cs:0.239017,638.115116) {};
          
        \node[coordinate,pin={[pin distance=0.25 in,pin edge={gray,thick}]90:{(4) $F_{t}=F_{ut}*(\frac{\epsilon_{t}}{\epsilon_{ut}})^n$} } ]
            at (axis cs:0.095,565) {};            

    \node[inner sep=0pt] (whitehead) at (axis cs:0.03,400)
    {\tiny{A}};

    \node[inner sep=0pt] (whitehead) at (axis cs:0.18,450)
    {\tiny{B}};

    %\node[inner sep=0pt] (whitehead) at (axis cs:0.33,350)
    %{\tiny{C}};
    
    \node[inner sep=0pt] (whitehead) at (axis cs:0.182322,680)
    {\tiny{B'}};    

    \node[inner sep=0pt] (whitehead) at (axis cs:0.1,160)
    {\tiny{Hardening Region}};    

    \addplot [<->, black, dashed, thick] coordinates {(0.012,439)  (0.012,0)};
    \addplot [<->, black,dashed, thick] coordinates {(0.2,512)  (0.2,0)};
    \addplot [<->, black, thick] coordinates {(0.012,100)  (0.2,100)};

    \addplot [<->, black, dashed, thick] coordinates {(0.29,350)  (0.29,0)};
    \addplot [<->, black, thick] coordinates {(0.2,100)  (0.29,100)};
    
    \node[inner sep=0pt] (whitehead) at (axis cs:0.245,160)
    {\tiny{Necking}};    
    
        %\node[inner sep=0pt] (whitehead) at (axis cs:0.245,180)
    %{\tiny$\begin{aligned} Necking, and \\ Fracture \end{aligned}$};    
    
    \node[inner sep=0pt] (whitehead) at (axis cs:0.31,350)
    {\tiny{C}}; 

\end{scope}
\end{axis}
\end{tikzpicture}
\end{center}
\caption{True Stress Strain Match}
\label{Tension_Test}
\end{figure}
\end{frame}
\end{document}

相关内容