여러 축에 동일한 스타일/옵션을 제공하는 방법

여러 축에 동일한 스타일/옵션을 제공하는 방법

작은 문제에 대해 다시 한 번 여러분의 의견을 듣고 싶습니다.

여러 플롯의 스타일을 설명하는 데 사용하고 싶지만 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}

관련 정보