It is possible to perform a general affine coordinate transformation in TikZ by combining the shift
, x
, and y
keys (or just the generalized cm
key to set the coordinate matrix and shift). This allows one to write natural-looking code to draw, for example, a shifted, slanted, skewed parabola:
\tikzset{shift = {(2,3)}, x = {(1,-2)}, y = {(5,1)}}
\draw plot (\x, \x^2);
I don't use TikZ to plot functions, because drawing the axes and handling scaling is a pain; I use pgfplots
. Unfortunately, because of the way that package implements the solution to the scaling problem, there is no direct connection between its coordinates and those of the surrounding TikZ picture, which means that these same keys do not have the desired effect when passed inside an axis
.
Now, I know that there is such a thing as axis cs
and axis direction cs
, and I also know what the section on "TikZ interoperability" says, but neither does what I want. The former works if I'm drawing a TikZ picture, and the latter makes me responsible for the size of the axes. It does not appear that using, say, shift = {(axis direction cs:2,3)}
actually places the computational origin (as compared to the axis origin, which had better stay at the original (0,0)
!) at the axis coordinates (2,3)
(nor does any of the other two obvious alternative coordinate systems). I want the following:
A way to make a local change of coordinates, inside a
scope
, that shifts plots given via\addplot
according to an affine transformation.pgfplots
transparency in this change: I want to be able to use its scaled coordinates obliviously.
It would be wonderful if there were affine transformations among the options available to data cs
but it only does polar. I am not enthusiastic about figuring out how to use \pgfplotsdefinecstransform
just to make it do this simple thing, either.
Here is an example that should work with such a solution:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}\begin{axis}
% What I want to write
\begin{scope}[ % Equivalent of:
% shift = {(0.5,0.5)},
% x = {(1,-1)},
% y = {(2, 1)},
%% Other options, such as:
/pgfplots/every axis plot/.append style = {very thick}
]
\addplot ({0.5*exp(x)}, {0.75*exp(-x)});
\end{scope}
% What I now have to write
\begin{scope}[
/pgfplots/every axis plot/.append style = {very thick}
]
\addplot ({0.5 + 0.5*exp(x) + 0.75*2*exp(-x)},
{0.5 + 0.5*-1*exp(x) + 0.75*exp(-x)});
\end{scope}
\end{axis}\end{tikzpicture}
\end{document}
I think you can see why I'd want this. (For the curious, I'm drawing trajectories of some solutions to systems of linear ODEs.)
x coord trafo
andy coord trafo
only accept one argument, x and y respectively. You cannot transform a x coordinate based on the x and the y value. Maybe the best solution is to implement a\pgfplotsdefinecstransform
that uses three key-values (i.e. a shift, x and y). – Qrrbrbirlbel Apr 1 '13 at 3:20