动态隐藏和显示绘图

动态隐藏和显示绘图

我想知道是否有可能做这样的事情,axis使用tikzpicture

在此处输入图片描述

我目前正在以这种方式绘制曲线:

\documentclass{article}

\usepackage[latin1]{inputenc}    
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{pgf,tikz}
\usetikzlibrary{fit}
\usetikzlibrary{arrows,patterns}
\usepackage{amsmath,siunitx,xcolor}
\usepackage{pgfplotstable,pgfplots,filecontents}
\pgfplotsset{compat=1.6} %Update pgfplots package version.
\usepackage{lscape,rotating,pdflscape}

\begin{document}

\begin{landscape}
\begin{tikzpicture}
\begin{axis}[
width=22cm,height=12cm,
legend columns=1,grid=both, legend cell align={left},
ymin=-4,ymax=4,xmin=0,xmax=4,
xlabel = Lenght L (m),ylabel = Wave amplitude A (-),
]
\addplot[domain=0:4,samples=200,red] {2*sin(2*pi/4*deg(x))};
\addplot[domain=0:4,samples=200,blue] {2*sin(2*pi/5*deg((x))};
\addlegendentry{Wave1}
\addlegendentry{Wave2}
\end{axis}
\end{tikzpicture}
\end{landscape}

\end{document}

答案1

要编译两次。使用Adobe 阅读器、Foxit 阅读器、(证明?)或管理 PDF 阅读器OCG层

ocgx我只是改编了和包中给出的示例代码ocgx2。最后的润色工作就交给你了。

\documentclass{article}

\usepackage[latin1]{inputenc}    
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage[top=1.5cm, bottom=4cm, left=2cm, right=2cm]{geometry}
%\usepackage{pgf,tikz}
\usepackage[tikz]{ocgx2} 
\usetikzlibrary{backgrounds,calc,shadows,chains,shapes.geometric}
\usetikzlibrary{fit}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows,patterns}
\usepackage{amsmath,siunitx,xcolor}
\usepackage{pgfplotstable,pgfplots,filecontents}
\pgfplotsset{compat=1.6} %Update pgfplots package version.
\usepackage{calculator,float}
\usepackage{lscape,rotating,pdflscape}

\tikzset{%
  button on/.style={%
    draw,minimum size=5mm,
    line width=1pt,
    fill=blue!50,rounded corners,
    switch ocg with mark on={#1}{},
  },
}
\begin{document}

\begin{landscape}
\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[
width=22cm,height=12cm,
legend columns=1,grid=both, legend cell align={left},
ymin=-4,ymax=4,xmin=0,xmax=4,
xlabel = Lenght L (m),ylabel = Wave amplitude A (-),
]
\begin{scope}[ocg={name=Wawe1 example,ref=Wawe1,status=invisible}]
\addplot[domain=0:4,samples=200,red] {2*sin(2*pi/4*deg(x))};
\end{scope}

\begin{scope}[ocg={name=Wawe2 example,ref=Wawe2,status=invisible}]
\addplot[domain=0:4,samples=200,blue] {2*sin(2*pi/5*deg((x))};
\end{scope}

\addlegendentry{Wave1}
\addlegendentry{Wave2}
\end{axis}
    \node[button on=Wawe1]at (-2,10)(but){};
    \node[right=0 of but]{Wawe1};
    \node[below=3pt of but,button on=Wawe2](but){};
    \node[right=0 of but]{Wawe2};
\end{tikzpicture}
\end{figure}
\end{landscape}

\end{document}

截屏


如果您不希望从一开始就看到这些功能,则必须使用 键switch ocg with mark off,而不是switch ocg with mark on

这就是给出的结果:

\tikzset{%
  button on/.style={%
    draw,minimum size=5mm,
    line width=1pt,
    fill=blue!50,rounded corners,
    switch ocg with mark off={#1}{},
  },
}

答案2

对于 2 个功能,我们有2^2=4可能性。对于更多功能,代码将会更加复杂。

在全屏模式下,单击复选标记即可导航到 pdf 页面并查看功能。

在此处输入图片描述

在此处输入图片描述

中(中)

\documentclass[tikz,margin=2mm]{standalone}
\usepackage{pgfplots,amssymb}
\usepackage[hidelinks]{hyperref}
\newcommand{\colorOn}{green!80!black}
\newcommand{\colorOff}{black!30}
\begin{document}
\foreach \i in {0,1}{
\foreach \j in {0,1}{
  \begin{tikzpicture}
  \begin{axis}[
  width=22cm,height=12cm,
  legend columns=1,grid=both, legend cell align={left},
  ymin=-4,ymax=4,xmin=0,xmax=4,
  xlabel = Lenght $L$ (m), ylabel = Wave amplitude $A$ (-),
  ]
  \ifnum \i=1 
    \addplot[domain=0:4,samples=200,red] {2*sin(2*pi/4*deg(x))}; 
    \addlegendentry{Wave1}
  \fi
  \ifnum \j=1 
    \addplot[domain=0:4,samples=200,blue] {2*sin(2*pi/5*deg((x))}; 
    \addlegendentry{Wave2}
  \fi
  \end{axis}
  \node[anchor=east,minimum width=4cm] (f) at (-2,6) {%
    $f(x)=2\sin(\frac{2\pi}{4}\deg(x))$
    \ifnum \i=0
      \ifnum \j=0
        \hypertarget{fOffgOff}{}%
        \hyperlink{fOngOff}{\textcolor{\colorOff}{\checkmark}} 
      \else
        \hypertarget{fOffgOn}{}%
        \hyperlink{fOngOn} {\textcolor{\colorOff}{\checkmark}} 
      \fi 
    \else 
      \ifnum \j=0
        \hypertarget{fOngOff}{}%
        \hyperlink{fOffgOff}{\textcolor{\colorOn}{\checkmark}} 
      \else
        \hypertarget{fOngOn}{}%
        \hyperlink{fOffgOn} {\textcolor{\colorOn}{\checkmark}} 
      \fi 
    \fi
  };
  \node[below of=f] (g)  {%
    $g(x)=2\sin(\frac{2\pi}{5}\deg(x))$ 
    \ifnum \i=0
      \ifnum \j=0
        \hyperlink{fOffgOn}{\textcolor{\colorOff}{\checkmark}} 
      \else
        \hyperlink{fOffgOff} {\textcolor{\colorOn}{\checkmark}} 
      \fi 
    \else 
      \ifnum \j=0
        \hyperlink{fOngOn}{\textcolor{\colorOff}{\checkmark}} 
      \else
        \hyperlink{fOngOff} {\textcolor{\colorOn}{\checkmark}} 
      \fi 
    \fi
  };
  \end{tikzpicture}
}}
\end{document}

相关内容