
pgfplots 環境で、主軸、副軸、および x 軸に対する角度に基づいて楕円を描くのに問題がありますaxis
。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}
出力: