TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How should this code be updated so that it does not require the compat=1.9 key?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
  \begin{tikzpicture}[baseline]
    \begin{axis}[
      axis lines=left,
      xtick=\empty,
      ytick=\empty,
      tiny,
      ylabel=Edible Resources,
      xlabel=Nutritional Need,
      title=Distribution of Edibles,
      title style={font=\tiny},
      ]
      \addplot[ domain=0:10, color=blue ] {2*x};
    \end{axis}
  \end{tikzpicture}%
\end{document}

target output (with <code>compat=1.9</code>)

If I remove the compat key, the axis labels are much too far from the axes.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}[baseline]
    \begin{axis}[
      axis lines=left,
      xtick=\empty,
      ytick=\empty,
      tiny,
      ylabel=Edible Resources,
      xlabel=Nutritional Need,
      title=Distribution of Edibles,
      title style={font=\tiny},
      ]
      \addplot[ domain=0:10, color=blue ] {2*x};
    \end{axis}
  \end{tikzpicture}%
\end{document}

without <code>compat</code>

I tried searching the pgfplots manual for 'likely-seeming' keywords and, also, for things such as \empty, but I could not find anything and ended up giving up.


Part of my motivation for asking this is that I'm generally unclear what the status of compat keys is for pgfplots. In most cases, I assume that compat keys are temporary quick-fixes to get existing code to work. However, I'm not certain whether that is correct for pgfplots or whether I should not even be asking this question.

That is, unlike other packages, maintaining backwards compatibility in pgfplots's case seems to consist of providing compat keys. So is there simply no expectation that the same code will produce the same result? Is it really best practice to always specify a compat key when using pgfplots and not then to change it? If so, how should cases be handled where I want to use plots from different documents in a new document, where the previous documents use different values for compat? Can I simply keep switching mid-document? Is that wise?

share|improve this question
2  
When I have understood you right, then I guess it is the other way round than you expect. When you use the compat key, this activates new features instead of old ones. This is explained in detail in section 2.2 in the PGFPlots manual. There it is also explained, that you can switch the compat level wherever you want inside the document and other stuff. – Stefan Pinnow 9 hours ago
    
@StefanPinnow But the old code I tried to compile didn't have a compat key at all. Yet it produced the plots I now need compat=1.9 to create. But if I've understood you correctly, compiling without compat now should have given me identical results to those I got compiling without compat three years ago. So I'm really confused. I assumed that something new explained why I needed the compat=1.9 to reproduce the same results as three years ago. Now I have no idea. – cfr 9 hours ago
    
Yes, you got me right. That should be the case. Actually you "only" need compat=1.3 to make the plot look like your "old" version and that is exactly what I have in mind and can be read in section 2.2.1 in the manual. Are you (absolutely) sure that you didn't have a compat level active in your old document? Or do you remember which version of PGFPlots you used at that time? – Stefan Pinnow 9 hours ago
    
@StefanPinnow It is not really an old document. It is actually the same document. I'd just made some changes. But I didn't touch the plot code or anything like that. I certainly did not delete a compat key. I discovered I needed it when I got weird results. So I assumed that was because something new had made things go haywire. I used 1.9 because that's what I found I used in another document written around the same time, so I thought that would be back enough. I have no idea which version of pgfplots I had, though. Whatever was in TL 2013, I expect. (Just maybe TL 2014.) – cfr 8 hours ago
    
@StefanPinnow In my defence, compat keys are usually for backwards compatibility, aren't they? And, to be honest, if I'd thought about it, I would have thought that must be the case here given my results .... – cfr 8 hours ago

When creating a new plot you should use the highest possible compat setting to be able to use all new features and the newest code. Currently this is

\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

When moving a plot from an older document with an lower compat to a new document take the lower compat level as an indication "Attention something could break!".

So test the plot with a higher level and compare with the older output. If the new output is okay (which it will be in quite a number of cases) there is nothing to do. If the output is faulty you can either adapt the code of the plot, or locally change the compat level:

\begin{figure}
\pgfplotsset{compat=1.4}
...
\caption{...}
\end{figure}

The documentation (2.2.2 Old Features Which May Need Attention ff) mentions some more keys that you can use to adapt an older plot to a newer pgfplots version.

share|improve this answer

Don't remove \pgfplotsset{compat=...}, simply put \pgfplotsset{compat=newest}.

However, there are contraindications. If future compatibility is a problem for you, just put \pgfplotsset{compat=1.14}.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
    \begin{tikzpicture}[baseline]
    \begin{axis}[
    axis lines=left,
    xtick=\empty,
    ytick=\empty,
    tiny,
    ylabel=Edible Resources,
    xlabel=Nutritional Need,
    title=Distribution of Edibles,
    title style={font=\tiny},
    ]
    \addplot[ domain=0:10, color=blue ] {2*x};
    \end{axis}
    \end{tikzpicture}%
\end{document}

enter image description here

share|improve this answer
1  
Christian Feuersänger advices against that actually, because then there is a possibility that a plot can change just because the package is updated. – Torbjørn T. 3 hours ago
    
@TorbjørnT. I've added a note, let me know if it could be OK now, thank you! – CarLaTeX 3 hours ago

In my opinion, the compat mechanism is one of the better feature of the pgfplots package. It allows the author to add, change or correct behavior without breaking old documents, that will continue working correctly.

As an example, I have a lot of pre-1.11 graphs in my documents. They are perfectly working now even if at 1.11 the (good!) switch to axis cs as default coordinate system was made. In new documents, I really like the new default, but it would have been a pain to change all the old documents... Best of two worlds.

As a counterexample, I was bitten by the change to the order of atn2 argument several times...

So I think your problem is the other way around. If you prepared your document pre-1.3, you probably noticed the problem, and manually shifted the labels. With no compat, or compact less than 1.3, the document will still be compiled correctly. In a world without the compat feature, the author would have fixed the bug, and now you will have to reedit your document to fix the overshifting.

When you are preparing new graphs, you should use the compat level of the version of the pgfplots you have at the moment. That way, this will works unchanged in the future. And give a warning if someone is trying to compile it with a too old version of pgfplots.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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