2

Using \groupplot, subplots are generated starting from the upper left corner as shown in the following illustration: enter image description here

Is it possible to force it to start from the bottom left corner, i.e :

enter image description here

Here is a MWE (As mentionned, mine hase 104 plots so it can't be considered as MWE):

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{groupplots}

\begin{document}
    \begin{tikzpicture} 
        \begin{groupplot}[group style={group size=2 by 2, horizontal sep=4em}]
            \nextgroupplot[xlabel=$x$, ylabel={$f(x) = x^2 - x +4$}]
                \addplot {x^2 - x +4};

            \nextgroupplot[group/empty plot]

            \nextgroupplot[xlabel=$x$, ylabel={$f(x) = x^2 - x +4$}]
                \addplot {x^2 - x +4};

            \nextgroupplot[xlabel=$x$, ylabel={$f(x) = x^2 - x +4$}]
                \addplot {x^2 - x +4};
        \end{groupplot}     
    \end{tikzpicture}
\end{document}

Ofcourse, If i had only 3 or four plots, I can simply reorganize my document. But I have 104 subplots!

  • Hi ! Could you show us a MWE ? – flav Apr 3 '16 at 9:04
  • 1
    This would take some modifications of the groupplots library I think. Rearranging things in Matlab isn't an option? – Torbjørn T. Apr 3 '16 at 9:59
  • Unfortunatelly rearranging this in Matlab isn't possible as I don't have access to Matlab anymore. – user2536125 Apr 3 '16 at 10:09
3
+50

One way of doing it is to change some lines in the groupplots library. To avoid having a very lengthy answer I suggest editing a copy of the source file of that library and changing the lines in that copy.

Have a look at the comments in the following code for more details.

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
    % copy the file
    %     `tikzlibrarypgfplots.groupplots.code.tex'
    % to the folder of your main TeX file and rename it to
    %     `tikzlibrarypgfplots.groupplotsMOD.code.tex'.
    % In that file replace some lines with the following code and remove
    % (only) the first comment sign on each of the lines.
    % (Please note that the given numbers are the *original* line numbers.
    %  To avoid confusion I suggest replacing them in reverse order.)
    %
    % 214
    %% -----------------------------------------------------------------------------
    %%        % vertical order from top to bottom
    %%        at={($(\pgfplots@glob@TMPb.south)-(0,\pgfkeysvalueof{/pgfplots/group/vertical sep})$)},anchor=north,%
    %        % vertical order from bottom to top
    %        at={($(\pgfplots@glob@TMPb.north)+(0,\pgfkeysvalueof{/pgfplots/group/vertical sep})$)},anchor=south,%
    %% -----------------------------------------------------------------------------
    % 235
    %% -----------------------------------------------------------------------------
    %%                \ifnum\pgfplots@row=\pgfplots@group@rows\relax%
    %                \ifnum\pgfplots@row=1%
    %% -----------------------------------------------------------------------------
    % 250
    %% -----------------------------------------------------------------------------
    %%                        \ifnum\pgfplots@row=1 %
    %                        \ifnum\pgfplots@row=\pgfplots@group@rows\relax%
    %% -----------------------------------------------------------------------------
    % 317
    %% -----------------------------------------------------------------------------
    %%              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r1/.append style={xticklabel pos=upper}}%
    %              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@group@rows/.append style={xticklabel pos=upper}}%
    %% -----------------------------------------------------------------------------
    % 320
    %% -----------------------------------------------------------------------------
    %%            \foreach \pgfplots@row in {2,...,\pgfplots@group@rows} {%
    %            \pgfplotsgroupplotsmath@decrease\pgfplots@group@rows
    %            \foreach \pgfplots@row in {1,...,\pgfmathresult} {%
    %% -----------------------------------------------------------------------------
    % 329
    %% -----------------------------------------------------------------------------
    %%              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@group@rows/.append style={xticklabel pos=lower}}%
    %              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r1/.append style={xticklabel pos=lower}}%
    %% -----------------------------------------------------------------------------
    % 331-332
    %% -----------------------------------------------------------------------------
    %%            \pgfplotsgroupplotsmath@decrease\pgfplots@group@rows
    %%            \foreach \pgfplots@row in {1,...,\pgfmathresult} {%
    %            \foreach \pgfplots@row in {2,...,\pgfplots@group@rows} {%
    %% -----------------------------------------------------------------------------
    \usepgfplotslibrary{groupplotsMOD}
    \pgfplotsset{
        compat=1.3,
    }
\begin{document}
    \begin{tikzpicture}
        \begin{groupplot}[
            group style={
                group size=2 by 2,
                horizontal sep=4em,
                xticklabels at=edge bottom,
                xlabels at=edge bottom,
            },
            xlabel=$x$,
            ylabel={$f(x) = x^2 - x +4$},
        ]
            \nextgroupplot
                \addplot {x^2 - x + 4};

            \nextgroupplot[group/empty plot]

            \nextgroupplot
                \addplot {x^2 - x + 4};

            \nextgroupplot
                \addplot {x^2 - x + 4};
        \end{groupplot}
        \draw [thick,>=latex,->,red]
            (group c1r1.center) node {1.} -- (group c2r1.center) node {2.};
        \draw [thick,>=latex,->,red]
            (group c2r1.center) -- (group c1r2.center) node {3.};
        \draw [thick,>=latex,->,red]
            (group c1r2.center) -- (group c2r2.center) node {4.};
    \end{tikzpicture}
\end{document}

image showing the result of above code

  • 1
    Thanks, this works. But the xticklabels are printed at the wrong subplots. I want to delete all xticklabels except at the bottom row. With your solution, they are printed at the top row. One more question: Can I have only three (or two) yticlabels per subplot? say for example, the minimum , average and maximum of ydata/ subplot? – user2536125 Apr 3 '16 at 12:07
  • 1
    It would have been nice, if you would have put all your requirements directly to the question and not asking for additional needs later on. Because that could end in a never ending story. Nevertheless, have a look at my edited answer. – Stefan Pinnow Apr 3 '16 at 21:01
  • 1
    Regarding the yticklabels: This truly is a new/separate question which already was asked before here. So far it seems that nobody has a good idea for that. Maybe you could have at the Feature Request Tracker of PGFPlots and add it there, if it shouldn't be in already. – Stefan Pinnow Apr 3 '16 at 21:04
  • 1
    You are right about the requirements, my bad. I just didn't notice it at the beginning. I am accepting your answer – user2536125 Apr 4 '16 at 7:10

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.