1

Using Matlab2tikz I generated a file containing 104 subplots aligned in a very specific manner. I then inserted \pgfplotsset{yticklabel style={text width=2em,align=right},}, compiled and obtained the final PDF which was fine, except the subplots arrangement is still not satisfactory:

enter image description here

I am trying to organize better the subplots such that:

  1. there will be the same vertically spacing,
  2. Only two ylabels per subplot

Is there a possibility to do this, without having to modify every single addplot?

Update: Using the solution proposed from Stefan Pinnow, I noticed that the order is still wrong. This is because the generated *.tikz file started from the second subplot (from the left) in the bottom row and positioned following subplots relative to it. This of course made the resulting figure using groupplot completely wrong. Hence, I think i am obliged to stick to the axis environment, and play on the yticklabels to improve the spacing.

Any idea how to automatically fix three yticklabels per subplot?

1 Answer 1

3
  1. I think the easiest (consistent) way to implement this is using the groupplots library (have a look at section 5.8 of the PGFPlots manual on page 428ff (in v1.13).
  2. Since you haven't specified exactly what "two ylabels" you need, I suggest playing a bit with the keys max space between ticks and try min ticks. Other keys of interest could be ytick (in combination with ytick distance) or yticklabels from table. All of these keys could be given as optional arguments to the \nextgroupplot command directly or - in case they should be repeated themselves - as styles which you can define in the preamble.

Please find a really simple example for the groupplot environment below.

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{groupplots}
\begin{document}
    \begin{tikzpicture}
        \begin{groupplot}[
            tiny,
            /tikz/mark size=1.5pt,
            group style={
                group name=my plots,
                group size=2 by 2,
                horizontal sep=4mm,      % <-- default: 1cm
                vertical sep=2mm,        % <-- default: 1cm
                xticklabels at=edge bottom,
            },
            width=3cm,
            height=3cm,
        ]
        \nextgroupplot[group/empty plot]
        \nextgroupplot
            \addplot coordinates{(0,0) (1,2) (2,1)};
        \nextgroupplot
            \addplot coordinates{(0,0) (1,2) (2,1)};
        \nextgroupplot
            \addplot coordinates{(0,0) (1,2) (2,1)};
        \end{groupplot}
    \end{tikzpicture}
\end{document}

image showing the result of above code

3
  • But with this, I have to add 104 groupplotmanually! Isn't there a better way? Feb 21, 2016 at 19:46
  • @user2536125, no, you only need/have one groupplot environment, but you have to place 104 \nextgroupplot commands. And I cannot suggest another solution when you don't state more details on where the plots in your above picture are coming from, if there are patterns of plots for the alignment and stuff like that. In short, when you are more precise on what you have and what you need, there maybe a chance for a "better" solution ;) Feb 21, 2016 at 20:24
  • This worked and improved the spacing. However, it changed the order of subplots. I just asked in a seperate question about this issue. Maybe you can provide a solution? Apr 3, 2016 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .