1

I have two pgfplots axes next to each other with the same dimensions. The axes should be aligned and use the same axis scaling. This leads to a situation where I specify width, height and the x and y unit vectors. The result is that the specified unit vectors override the axis dimensions.

\documentclass[tikz,margin=10pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}

    \begin{axis}[
        width=6cm,
        height=6cm,
        x=5mm,
        y=5mm,
        ticks=none,
        name=ax1
    ]
    \addplot[only marks] coordinates {(-1,-1) (0,0) (1,1)};
    \end{axis}

    \begin{axis}[
        width=6cm,
        height=6cm,
        x=5mm,
        y=5mm,
        ticks=none,
        name=ax2,
        at={($(ax1.south east)+(2mm,0)$)},
    ]
    \addplot[only marks] coordinates {(9.5,10.5) (10,10) (10.5,9.5)};
    \end{axis}

\end{tikzpicture}
\end{document}

The MWE looks like this:

current situation, mwe

I would like it to look like this (achieved by setting actual axis limits, so the scaling is different):

expected outcome

The coordinates center is not at a known location, so I can't simply set the axis limits directly.

Is there a way to do this directly in pgfplots? Maybe tell pgfplots to use the same axis scaling between multiple plots? I looked through the Chapters 4.10 ("Scaling Options") and 4.14 ("Specifying the Plotted Range") of the pgfplots manual, but could not find a solution.

Otherwise I'm thinking of placing the axis environments (with fixed unit vectors) at the center of nodes of fixed size, so that the uniform scaling is preserved, and the outer boxes are the same.

1

Here's a hacky solution that just draws fixed size nodes and places the pgfplots axes in their center.

It achieves the visual goal asked in the question, but has two significant drawbacks to be generally useful:

  • If the contents are too large, they will exceed the node boundaries
  • If ticks or other labeling is needed, they will be displayed at the actual hidden axes
\documentclass[tikz,margin=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

    % Draw the visible plot boundaries as fixed size nodes
    \node[minimum width=6cm, minimum height=6cm, draw] (A) {};
    \node[minimum width=6cm, minimum height=6cm, draw, right=2mm of A] (B) {};

    % Draw the axis without axis lines, with specified scaling,
    % in the middle of the nodes
    \begin{axis}[
        axis line style={draw=none},
        anchor=center,
        x=5mm,
        y=5mm,
        ticks=none,
        at=(A.center),
    ]
    \addplot[only marks] coordinates {(-1,-1) (0,0) (1,1)};
    \end{axis}

    \begin{axis}[
        axis line style={draw=none},
        anchor=center,
        x=5mm,
        y=5mm,
        ticks=none,
        at=(B.center),
    ]
    \addplot[only marks] coordinates {(9.5,10.5) (10,10) (10.5,9.5)};
    \end{axis}

\end{tikzpicture}
\end{document}

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.