I'm trying to rotate the plotting of a parabola above a tikzpicture
. (For a parabola, I can achieve what I want without using pgfplots
, but I need the same for more complicated plots.) I can't seen to understand how the anchors for rotation work, neither how does the tikz
scaling impacts on them. What I've got so far:
The difference between the pictures is that the first has a scale=1.5
modifier added to the tikzpicture
. The blue parabola should be where the black one is (i.e., with center at b
). The green parabola is added only for visualization of a weird behavior.
-
About the scale. I've seen this, but as far as I understand, I don't use outside elements in my
pgfplot
calculations (only the origin placement). Hence scaling after the plotting is done should be no problem. Furthermore, as seen in the second figure, even when thescale
input is removed, the positioning and size of the parabolas is still incorrect. Why is it that thescale
is not working properly with thepgfplot
? How is it possible that the scaling moves the point(0,0)
upwards or downwards ("weird behaviour")? (maybe the second question is related to bad anchoring?)
Moreover, why is the blue parabola so big, even without scaling, if the plot domain is the same used for the black parabola? -
About the rotation. I took the approach from here and it seems to work fine, although with the wrong anchor. However, I don't understand fully its statement. I get that
rotate around={90:(current axis.origin)}
rotates around the second entry,(current axis.origin)
. But what is the current axis? What other options could I write instead of that?
I couldn't find anything about rotating the whole plot in thepgfplots
manual. -
About the anchoring. It doesn't work and I don't understand why not. Without the
at
option, the misplacement is even worse (and I actually need that option, because I want to manually set the plot placement, as done here). My understanding: theat
option fixes a pointA
in thetikzpicture
coordinates; then, theanchor
option takes a locationB
of thepgfplot
coordinates and fixes it in thetikzpicture
, directly overA
. Is this correct? If so, why is my code not working? The point(0,0)
is in the middle ofa
andb
and therefore placing the plot origin at(0,0)
and afterwards rotating the plot around its origin should be enough to place the blue parabola over the black one (and the green parabola overa
).
Of course a running code is welcome, but mostly I want to understand how this placement works, so that I can use it for other complicated plots as well. Thank you in advance!
MWE:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
%\pgfplotsset{compat=1.15} %this line removes the warning but cuts the picture
\begin{document}
\begin{tikzpicture}
[scale=1.5] %remove this line for figure 2
\coordinate (a) at (-1,0);
\coordinate (b) at (1,0);
\coordinate (o) at (0,0);
%draw reference line
\filldraw (a) node[below]{$a$} (a) {} circle (0.3pt);
\filldraw (b) node[below]{$b$} (b) {} circle (0.3pt);
\draw[-] (-1.5,0)--(1.5,0);
%these are out of scale and misplaced
\begin{axis}[at={(o)}, %where the origin is supposed to be
anchor=origin, % i have tried center as well
rotate around={-90:(current axis.origin)}, % Supposed to rotate around the origin
domain=-1:1,
hide axis]
\addplot[blue] {x^2+1};
\end{axis}
\begin{axis}[at={(o)}, %where the origin is supposed to be
anchor=origin, % i have tried center as well
rotate around={90:(current axis.origin)}, % Supposed to rotate around the origin
domain=-1:1,
hide axis]
\addplot[green] {x^2+1};
\end{axis}
%what it should be
\draw[black, rotate=-90] plot[smooth,domain=-1:1] (\x, {(\x)^2+1});
\end{tikzpicture}
\end{document}
Best Answer
To scale the plot, adjust the width (height).
This attempts to move the pgfplots instead. Not quite sure where the small offsets are coming from.