pgfplot 축 환경에서 타원의 크기 조정 및 회전이 제대로 이루어지지 않습니다.

pgfplot 축 환경에서 타원의 크기 조정 및 회전이 제대로 이루어지지 않습니다.

axisx축의 주요 축, 보조 축 및 각도를 기반으로 pgfplots 환경에서 타원을 그리는 데 문제가 있습니다 . Tikz를 사용하여 이러한 타원을 그릴 수 있었지만 각도 회전이 축 사이의 종횡비를 제대로 따르지 않습니다. 이것이 의미하는 바는 너비와 높이가 고정되어 있고 종횡비가 동일한 그림의 경우 각도가 45°인 경우 x축 범위를 늘리면 타원이 "눌려지고" 각도도 커진다는 것입니다. . 그렇다면 "화면"뿐만 아니라 좌표계 자체로 타원을 어떻게 회전합니까? 감사해요!

MWE:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \draw[draw=blue] (axis cs:1,1) ellipse [x radius=0.25, y radius=0.5, rotate=45];
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \draw[draw=blue] (axis cs:1,1) ellipse [x radius=0.25, y radius=0.5, rotate=45];
    \end{axis}
\end{tikzpicture}

\end{document}

산출:

타원

원하는 것:

명확히 하기 위해 이것이 제가 찾고 있는 것입니다. 따라서 Jasper Habicht의 솔루션 라인을 따라 (axis cs:1,1) ellipse [x radius=0.25*\a, y radius=0.5*\b, rotate=45*\c], \a\b\c종횡비와 이미지 너비를 기반으로 계산됩니다.

원하는

답변1

이것이 무슨 뜻인지는 확실하지 않지만 너비와 높이를 축 단위로 나누어 회전 각도를 계산한 다음 아크탄 탄탄값을 얻을 수 있지만 이것이 실제로 올바른 출력 결과를 가져올지는 확실하지 않습니다.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \pgfmathsetmacro{\a}{
            atan(
                (\pgfkeysvalueof{/pgfplots/width}/(\pgfkeysvalueof{/pgfplots/xmax}-\pgfkeysvalueof{/pgfplots/xmin}))/
                (\pgfkeysvalueof{/pgfplots/height}/(\pgfkeysvalueof{/pgfplots/ymax}-\pgfkeysvalueof{/pgfplots/ymin})))
        }
        \draw[draw=blue] (1,1) ellipse [x radius=0.25, y radius=0.5, rotate=\a];
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \pgfmathsetmacro{\a}{
            atan(
                (\pgfkeysvalueof{/pgfplots/width}/(\pgfkeysvalueof{/pgfplots/xmax}-\pgfkeysvalueof{/pgfplots/xmin}))/
                (\pgfkeysvalueof{/pgfplots/height}/(\pgfkeysvalueof{/pgfplots/ymax}-\pgfkeysvalueof{/pgfplots/ymin})))
        }
        \draw[draw=blue] (1,1) ellipse [x radius=0.25, y radius=0.5, rotate=\a];
    \end{axis}
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요


가장 좋은 방법은 아마도 어떻게든 타원의 매개변수 함수를 계산하고 이를 플롯하는 것입니다. 이는 다음과 같습니다.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addplot[domain=0:360, samples=200, blue](
            {cos(x)*sqrt(0.33/(sin(2*x)+2))+1},
            {sin(x)*sqrt(0.33/(sin(2*x)+2))+1}
        );
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addplot[domain=0:360, samples=200, blue](
            {cos(x)*sqrt(0.33/(sin(2*x)+2))+1},
            {sin(x)*sqrt(0.33/(sin(2*x)+2))+1}
        );
    \end{axis}
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

답변2

Jasper Habicht의 제안 덕분에 알아냈습니다.이것포스트: 알고보니 생각보다 복잡하지 않더군요.

따라서 아래 코드를 사용하면 pgfplots중심 x, y와 x축의 주요, 보조 및 각도를 지정한 축 환경에서 타원을 그릴 수 있습니다.

MWE:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\newcommand{\addellipse}[5]{\addplot [domain=0:360, samples=50, draw=blue] ({(#3/2)*cos(x)*cos(#5) - (#4/2)*sin(x)*sin(#5) + #1}, {(#3/2)*cos(x)*sin(#5) + (#4/2)*sin(x)*cos(#5) + #2});}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        name=plot_left,
        scale only axis,
        height=35mm,
        width=15mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addellipse{1}{1}{1}{0.5}{45}
        );
    \end{axis}
    \begin{axis} [
        name=plot_right,
        at={(plot_left.north east)},
        anchor=north west,
        xshift=10mm,
        scale only axis,
        height=35mm,
        width=90mm,
        xmin=0,
        xmax=3,
        ymin=0,
        ymax=2,
    ]
        \addellipse{1}{1}{1}{0.5}{45}
        );
    \end{axis}
\end{tikzpicture}

\end{document}

산출:

적절한 크기 조정

관련 정보