如何為多個軸提供相同的樣式/選項

如何為多個軸提供相同的樣式/選項

我想在一個小問題上再請教您。

我想用來tikzstyle描述多個繪圖的樣式,但是當我複製並貼上在繪圖上使用的樣式時,出現編譯錯誤。

工作代碼:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\def\T{10}
\def\K{10}

\begin{tikzpicture}
    \tikzstyle{Bode}=[]
    \tikzstyle{Asymp}=[red,densely dashed,thick=1pt]
    \tikzstyle{LieuReel}=[thick=1pt]

    \def\FloorW{floor(ln(1/\T)/ln(10))}
    \def\CeilW{ceil(ln(1/\T)/ln(10))}
    \def\GdbK{20*ln(\K)/ln(10)}

    \begin{semilogxaxis}[height=5cm,width=10cm,xlabel=$\omega$,ylabel=$G_{dB}$,grid=both,axis x line=bottom, axis y line = left,ymax=(\GdbK+4),xmax=10^(\CeilW+2.2)]

        \addplot [domain=(10^(\FloorW-2)):(10^(\CeilW+2)),samples=50] {\GdbK-(10*(ln(\T^2*x^2+1)))/ln(10)}[LieuReel];

        \addplot [domain=(10^(\FloorW-2)):(1/\T),samples=2] {\GdbK}[Asymp];
        \addplot [domain=(1/\T):(10^(\CeilW+2)),samples=2] {\GdbK-(10*(ln(\T^2*x^2)))/ln(10)}[Asymp]; 
    \end{semilogxaxis}
\end{tikzpicture}

\end{document}

現在,我將我的風格放入semilogaxis其中並在其中tikzstyle{Bode}鍵入Bode

\tikzstyle{Bode}=[height=5cm,width=10cm,xlabel=$\omega$,ylabel=$G_{dB}$,grid=both,axis x line=bottom, axis y line = left,ymax=(\GdbK+4),xmax=10^(\CeilW+2.2)]
     ...
\begin{semilogxaxis}[Bode]

它給我這個錯誤:

! Package pgfkeys Error: I do not know the key '/tikz/height', to which you passed '5cm', and I am going to ignore it. Perhaps you misspelled it.See the pgfkeys package documentation for explanation.Type H <return> for immediate help.... \end{semilogxaxis}

你能幫助我嗎 ?

答案1

\tikzstyle{foo}=[..]或替換在鍵系列\tikzset{foo/.style={..}}中查找,但是,並且其他參數屬於該系列,因此您會收到未知的錯誤。/tikzwidthheightaxis/pgfplots/tikz/width

相反,您可以使用\pgfplotsset{foo/.style={..}},則假定密鑰位於/pgfplots家庭中。

順便說一句,一般來說,最好使用\newcommand代替\def,因為這樣您就不會意外覆蓋現有的巨集。

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\newcommand\T{10}
\newcommand\K{10}

\begin{tikzpicture}[
  Asymp/.style={red,densely dashed,thick=1pt},
  LieuReel/.style={thick=1pt}
  ]


    \newcommand\FloorW{floor(ln(1/\T)/ln(10))}
    \newcommand\CeilW{ceil(ln(1/\T)/ln(10))}
    \newcommand\GdbK{20*ln(\K)/ln(10)}
    \pgfplotsset{
       bode/.style={
          height=5cm,
          width=10cm,
          xlabel=$\omega$,
          ylabel=$G_{dB}$,
          grid=both,
          axis x line=bottom,
          axis y line = left,
          ymax=(\GdbK+4),
          xmax=10^(\CeilW+2.2)}
          }
    \begin{semilogxaxis}[bode]

        \addplot [domain=(10^(\FloorW-2)):(10^(\CeilW+2)),samples=50] {\GdbK-(10*(ln(\T^2*x^2+1)))/ln(10)}[LieuReel];

        \addplot [domain=(10^(\FloorW-2)):(1/\T),samples=2] {\GdbK}[Asymp];
        \addplot [domain=(1/\T):(10^(\CeilW+2)),samples=2] {\GdbK-(10*(ln(\T^2*x^2)))/ln(10)}[Asymp]; 
    \end{semilogxaxis}
\end{tikzpicture}

\end{document}

相關內容