pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
198 stars 33 forks source link

enlarge x limits differently for upper/lower limits #396

Open juliangilbey opened 3 years ago

juliangilbey commented 3 years ago

Hi Christian,

What an amazing package this is - thank you!

I've been trying to develop a style for school textbook-like graphs, and I've mostly got there. What I would like to be able to do is to add a fixed amount of extra space at the ends of the graph; in particular, so that I can place the axis labels ("x", "y") without any fear of overlapping the graph itself.

Here's a very simple (and slightly silly) example:

\begin{tikzpicture}
  \begin{axis}[
    xmin=-1.5,xmax=1.5,
    ymin=-0.5,ymax=3,
    samples=30,
    domain=-1.5:1.5,
    enlarge x limits={upper,abs value={2cm}},
    %enlarge x limits={lower,abs value={0.5cm}},
    ]
    \addplot plot [mark=none] {x^2};
  \end{axis}
\end{tikzpicture}

As shown, this extends the upper limit of the x-axis by 2cm, which is great. (It also extends the axis ticks into this region as well, which is maybe not so good. I can fix that by specifying xtickmax, though.) However, if I uncomment the second enlarge x limits line, it overrides the first one; it seems that it is possible to specify an enlarge x limits for both directions equally, or for exactly one direction, but not for different amounts in the two directions.

It would be nice to have that facility, though I realise that it may be difficult to achieve within the restrictions of the current code.

Best wishes, Julian

Edit: I should have added my preamble:

\usepackage{pgfplots}
\pgfplotsset{
  compat=1.17,
  axis lines=center,
  xlabel=$x$,
  ylabel=$y$
}
cfeuersaenger commented 3 years ago

Hi Julian,

you are right, enlarge x limits accepts just one value and even if it is specified twice... you can file a feature request for it at github, though it might take a long time before it gets worked on.

Kind regards

Christian

Julian Gilbey ***@***.***> hat am 12.05.2021 14:25 geschrieben:

Hi Christian,

What an amazing package this is - thank you!

I've been trying to develop a style for school textbook-like graphs, and I've mostly got there. What I would like to be able to do is to add a fixed amount of extra space at the ends of the graph; in particular, so that I can place the axis labels ("x", "y") without any fear of overlapping the graph itself.

Here's a very simple (and slightly silly) example:

\begin{tikzpicture}
  \begin{axis}[
    xmin=-1.5,xmax=1.5,
    ymin=-0.5,ymax=3,
    samples=30,
    domain=-1.5:1.5,
    enlarge x limits={upper,abs value={2cm}},
    %enlarge x limits={lower,abs value={0.5cm}},
    ]
    \addplot plot [mark=none] {x^2};
  \end{axis}
\end{tikzpicture}

As shown, this extends the upper limit of the x-axis by 2cm, which is great. (It also extends the axis ticks into this region as well, which is maybe not so good. I can fix that by specifying xtickmax, though.) However, if I uncomment the second enlarge x limits line, it overrides the first one; it seems that it is possible to specify an enlarge x limits for both directions equally, or for exactly one direction, but not for different amounts in the two directions.

It would be nice to have that facility, though I realise that it may be difficult to achieve within the restrictions of the current code.

Best wishes, Julian

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/pgf-tikz/pgfplots/issues/396 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCGY3DPGINLG33CBROAJVTTNJXTJANCNFSM44YP4U4Q .