1

I'm trying to scale a pgfplots that uses group plots but something is not working properly. This is the MWE:

\documentclass{article}
\usepackage[%
  total={6in,9in},%
  body={111.5mm,185.6mm},%
  head=10pt,
  centering,showframe,
]{geometry}
\usepackage{showframe}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots, colorbrewer}
\usepackage{tikzscale}


\begin{document}
\includegraphics[width=1.\linewidth,axisratio=1]{group_plot.tikz}
\input{group_plot.tikz}
\end{document}

and the file group_plot.tikz is simply:

\begin{tikzpicture}[]

\begin{groupplot}[cycle list/Dark2, group style={group name=myplot, group size= 2 by 1, horizontal sep=0.5em}, every axis plot/.append style={line width=0.4mm, line join=round},
      axis lines = middle,
      enlargelimits = true,
      x axis line style = {thick,-stealth},
      y axis line style = {thick,-stealth},
       legend style={font=\footnotesize, at={(0.61,0)}, anchor=south, draw=none, yshift=-23pt, fill=white, fill opacity=0.9, 
      /tikz/every even column/.append style={column sep=0.2cm}},
      legend columns=3,
      xmin=-1,xmax=1,
      ymin=-1,ymax=1.,
%      every axis x label/.style={at={(current axis.east)}, yshift=3pt},
]

\nextgroupplot[
      cycle list name = Dark2,
      xlabel=$\xi$,
      ylabel={$\xi^i$},
      xtick={-1,1},
      ytick={1},
      every axis y label/.style={at={(current axis.north)}, xshift=8pt,yshift=-2pt},
    ]
    % use TeX as calculator:
    \addplot + [mark=none, domain=-1:1] {x};
\nextgroupplot[
      cycle list name = Dark2,
      xlabel=$\xi$,
      ylabel={$L_i(\xi)$},
      xtick={-1,1},
      ytick={1},
      every axis y label/.style={at={(current axis.north)}, xshift=15pt,yshift=-2pt},
    ]
    % use TeX as calculator:
    \addplot + [mark=none, domain=-1:1] {x};        
\end{groupplot}
\draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
            
\end{tikzpicture}

I get a result that doesn't make sense, with the error:

./group_plot.tikz:36: Package pgfplots Error: Error: Plot width `-6.1997pt' is too small. This cannot be implemented while maintaining constant size for labels. Sorry, label sizes are only approximate. You will need to adjust your width..

This is the result:

enter image description here

5
  • Isn't this the same issue as in tex.stackexchange.com/q/174013/47927 ? Jul 21, 2022 at 13:54
  • It's the same issue, but for some reason that post has code that compiles without problem and the one in this post doesn't.
    – aaragon
    Jul 22, 2022 at 7:25
  • Please create a MWE showing your problem. Delete all labels, styles, plots - everything that is not needed to show the error/unexpected behaviour. Jul 23, 2022 at 22:32
  • The code I wrote is pretty much a MWE, right?
    – aaragon
    Jul 24, 2022 at 8:48
  • My guess is that your code is not minimal. Is colorbrewer needed to recreate your problem? You already has an answer, so I guess it does not matter now. Jul 24, 2022 at 17:30

1 Answer 1

0
+50

I'm not entirely sure if this is the solution you are aiming. But I compile and got the same message with -6.1997pt etc. As I did just small changes following the linked answer cited in comments, I will only present these parts of the code, the rest remains intact.

Changes

Changes are:

  1. In your main file, \pgfplotsset{compat=1.10}. This is not mandatory, but results look nicer.
\usepackage{pgfplots}
\pgfplotsset{compat=1.10} % add
  1. In your group_plot.tikz add the following lines into \begin{groupplot}
\begin{groupplot}[
...
% add
  width=1/2*\textwidth-2.5cm,
  height=2.5cm
]

You edit the values in order to achieve the result you wish.

Those lines were the lines I noticed there weren't in your group define, but they were at the original one, besides, the log message wrote something about height and width, so that was my best guess.

  1. Not mandatory, but I reduced a little bit the size of the figure from 1 to 0.9 \linewidth in \includegraphics[width=0.9\linewidth,axisratio=1]{group_plot.tikz}.

Results

With \pgfplotsset{compat=1.10}.

enter image description here

Without \pgfplotsset{compat=1.10}.

enter image description here

You must log in to answer this question.

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