8

In gnuplot you can specify positions in several coordinate systems: First, Second, Graph, Screen, Character.

What are the equivalents in pgfplots? I know the following:

  • First : axis cs:
  • Second : axis cs: (manual suggests using two axis on top of each other)
  • Graph : rel axis cs:
  • Screen : can be done with the help of barycentric cs:
    \begin{axis}[name=s]
    \end{axis}
    \coordinate (topright) at (s.outer north east);
    \coordinate (bottomleft) at (s.outer south west);
    \node at (barycentric cs:bottomleft=0.5,topright=0.5) {CENTER};
    (possibly not the most convenient way and only available outside of \begin{axis}\end{axis})

How can one give x and y coordinate in different systems?

Example:

\documentclass{standalone}

\usepackage{pgfplots}
\usepackage{pgfplotstable} % For \pgfplotstableread
\pgfplotsset{compat=1.10}

\pgfplotstableread{
0.01    1.00
0.02    2.00
0.03    3.00
0.04    4.00
0.05    5.00
}\datatable

\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=6]
\addplot table  {\datatable};
\node at (axis cs:0.02,3) {A};
\node at (rel axis cs:0.66,0.5){B};
% \node at (rel axis cs:0.66, axis cs:1){C}; % HOW CAN I DO THIS?
\end{axis}
\end{tikzpicture}
\end{document}

Update

I figured out that there are many ways to specify coordinates using

  • different coordinate systems (default (i.e. without specifying): axis description cs),
  • predefined nodes,
  • predefined anchors, or
  • computed values.

Example using the predefined node current axis:

\usetikzlibrary{calc}
\coordinate (topleft) at ($(current axis.north west) + (-1.3cm,0.3cm)$);

These are described in following chapters of the pgfplots manual:

  • 4.9.1 Placement of Axis Descriptions
    coordinate systems: axis description cs, ticklabel cs
  • 4.9.2 Alignment of Axis Descriptions
    anchors near ticklabel, near ticklabel opposite
  • 4.14.2 Accessing Computed Limit Ranges
    \pgfkeysvalueof{/pgfplots/xmin}
    \pgfkeysvalueof{/pgfplots/xmax}
    \pgfkeysvalueof{/pgfplots/ymin}
    \pgfkeysvalueof{/pgfplots/ymax}
    \pgfkeysvalueof{/pgfplots/width}
    \pgfkeysvalueof{/pgfplots/height}
  • 4.17.1 Accessing Axis Coordinates in Graphical Elements
    coordinate systems axis cs, axis direction cs and rel axis cs
    nodes current plot begin current plot end
  • 4.17.2 Placing Nodes on Coordinates of a Plot
    \tikz\pos={<fraction>}
  • 4.19 Alignment Options (!)
    node current axis with
    anchors center, outer center, outer north west, north west, left of north west, origin, left of origin, ...

  • 4.20 The Picture’s Size: Bounding Box and Clipping
    \pgfresetboundingbox, trim

  • 4.24 Transforming Coordinate Systems
    coordinate system data cs
  • 5.7 Grouping plots
    anchor c<x>r<x>.center/left/right

Relevant sections of the pgf manual:

  • 17.5.1 Positioning Nodes Using Anchors - center, north west, north, north east, east, south east, south, south west, west, base, mid
  • 17.5.2 Basic Placement Options - above/below/right/left, above left/right, below left/right
  • 17.5.3 Advanced Placement Options - \usetikzlibrary{positioning}
6

As far as I know you can't address components of different coordinate systems. In fact, I don't think it makes too much sense. However, you can use orthogonal identifiers such as

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\usepackage{pgfplotstable} % For \pgfplotstableread
\pgfplotsset{compat=1.10}

\pgfplotstableread{
0.01    1.00
0.02    2.00
0.03    3.00
0.04    4.00
0.05    5.00
}\datatable

\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=6]
\addplot table  {\datatable};
\node at (axis cs:0.02,3) {A};
\node at (rel axis cs:0.66,0.5){B};
\node at ({rel axis cs:0.66,0}|-{axis cs:0,1}){C}; %<=== Like this
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.