3

I have a problem to rotate an axis. Here is the code I use where the problem occurs : the two axis origins are not aligned.

\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}

BUT, if I remove the line :

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

the problem disapears and the axis are aligned ... Could someone tell me why please ?

Thanks !

1 Answer 1

2

Your mistake is that you specify ymin=-1 and use a coordinate (4.,-2). Hence the rotation around (0,0) gets confused in an attempt to adjust. You can see this if you put ymin=-2

enter image description here

But if you want to have ymin=-1, then you will have to change the point about which things are rotated. A good choice will be

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

With this you get

enter image description here

Code:

\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}
4
  • Oh, I did not know it was possible to specify (rel axis cs:0,0). Thank you very much !
    – StormRider
    Commented Sep 3, 2014 at 9:21
  • @user52730 Thanks are better converyed in this site by upvoting and accepting the answer/s that helped you. For details, please refer to: How do you accept an answer
    – user11232
    Commented Sep 3, 2014 at 14:16
  • Oh sorry, I did not know that, I'm going to accept answers in my previous posts ... :)
    – StormRider
    Commented Sep 3, 2014 at 15:10
  • @user52730 It's OK. It happens :-). And thank you very much. Happy TeXing.
    – user11232
    Commented Sep 4, 2014 at 2:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .