轴旋转和对齐

轴旋转和对齐

我在旋转轴时遇到问题。这是我使用的代码,问题发生的地方:两个轴原点未对齐。

\documentclass[a4paper,11pt,twoside]{article}
\usepackage[pdftex, active, floats, tightpage]{preview}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{figure}
\begin{tikzpicture}
    [/pgfplots/y=5cm, /pgfplots/x=5cm]
    \begin{axis}[
    xmin=0.,xmax=2.,ymin=-1.,ymax=1.
    , x=1cm, y=1cm
    , xlabel={x}, ylabel={y}
    , axis x line=bottom, axis y line=left
    , anchor=origin
    , ticks=none
    , xlabel={}, ylabel={}
    , clip=false
    ]
    \draw[red, solid] (axis cs:0,0) ellipse [x radius=1,  y radius=1];
    \draw[black, thick] (axis cs:1.5, -1.) to[bend left=-20] (axis cs:1.41, -0.487);
    \node at (axis cs:1.42,-0.73) [anchor=west] {$\theta$};
    \node at (axis cs:2,-1) [anchor=north, black] {$x$};
    \node at (axis cs:0,1) [anchor=east, black] {$y$};
    \end{axis}

    \begin{axis}[
    xmin=0.,xmax=6.,ymin=-1.,ymax=1.
    , x=1cm, y=1cm
    , xlabel={x'}, ylabel={y'}
    , axis x line=bottom, axis y line=left
    , rotate=20
    , anchor=origin
    , ticks=none, color=green!80!black
    , xlabel={}, ylabel={}
    , clip=false
    ]
    \draw[red, dashed, thick] (axis cs:0,0) ellipse [x radius=1,  y radius=1];
    \draw[blue, dashed](axis cs:4.,-2)--(axis cs:4.,0);
    \node at (axis cs:6,-1) [anchor=north, green!80!black] {$n$};
    \node at (axis cs:0,1) [anchor=east, green!80!black] {$t$};
    \addplot [blue, mark=x, nodes near coords=$A$, every node near coord/.style={anchor=north west, yshift={0.3em}}] coordinates {(4.,-1)};
    \addplot [blue, mark=x, nodes near coords=$B$, every node near coord/.style={anchor=west}] coordinates {(4.,-2)};
    \addplot [blue, mark=x, nodes near coords=$C$, every node near coord/.style={anchor=west}] coordinates {(4.,0.)};
    \end{axis}

\end{tikzpicture}
\end{figure}

\end{document}

但是,如果我删除该行:

\addplot [blue, mark=x, nodes near coords=$B$, every node near coord/.style={anchor=west}] coordinates {(4.,-2)};

问题消失并且轴对齐...有人能告诉我为什么吗?

谢谢 !

答案1

你的错误在于你指定ymin=-1并使用了坐标。因此,为了调整,(4.,-2)旋转会变得混乱。如果你输入(0,0)ymin=-2

在此处输入图片描述

但是如果你想要ymin=-1,那么你必须改变旋转点。一个好的选择是

, rotate around={20:(rel axis cs:0,0)}

有了这个,你可以

在此处输入图片描述

代码:

\documentclass[a4paper,11pt,twoside]{article}
\usepackage[pdftex, active, floats, tightpage]{preview}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{figure}
\begin{tikzpicture}
    [/pgfplots/y=5cm, /pgfplots/x=5cm]
    \begin{axis}[
    xmin=0.,xmax=2.,ymin=-1.,ymax=1.
    , x=1cm, y=1cm
    , xlabel={x}, ylabel={y}
    , axis x line=bottom, axis y line=left
    , anchor=origin
    , ticks=none
    , xlabel={}, ylabel={}
    , clip=false
    ]
    \draw[red, solid] (axis cs:0,0) ellipse [x radius=1,  y radius=1];
    \draw[black, thick] (axis cs:1.5, -1.) to[bend left=-20] (axis cs:1.41, -0.487);
    \node at (axis cs:1.42,-0.73) [anchor=west] {$\theta$};
    \node at (axis cs:2,-1) [anchor=north, black] {$x$};
    \node at (axis cs:0,1) [anchor=east, black] {$y$};
    \end{axis}

    \begin{axis}[
    xmin=0,xmax=6.,ymin=-1.,ymax=1.
    , x=1cm, y=1cm
    , xlabel={x'}, ylabel={y'}
    , axis x line=bottom, axis y line=left
    , rotate around={20:(rel axis cs:0,0)}
    , anchor=origin
    , ticks=none, color=green!80!black
    , xlabel={}, ylabel={}
    , clip=false
    ]
    \draw[red, dashed, thick] (axis cs:0,0) ellipse [x radius=1,  y radius=1];
    \draw[blue, dashed](axis cs:4.,-2)--(axis cs:4.,0);
    \node at (axis cs:6,-1) [anchor=north, green!80!black] {$n$};
    \node at (axis cs:0,1) [anchor=east, green!80!black] {$t$};
    \addplot [blue, mark=x, nodes near coords=$A$, every node near coord/.style={anchor=north west, yshift={0.3em}}] coordinates {(4.,-1)};
    \addplot [blue, mark=x, nodes near coords=$B$, every node near coord/.style={anchor=west}] coordinates {(4.,-2)};
    \addplot [blue, mark=x, nodes near coords=$C$, every node near coord/.style={anchor=west}] coordinates {(4,0)};
    \end{axis}

\end{tikzpicture}
\end{figure}

\end{document}

相关内容