1

Consider the MWE below. This example is from the PGF Plot galery with added 1 outlier (1000,50) resulting in the first (wrong) screenshot below.

I want to limit the domain/axis, so I get something like the second screenshot but with the (1000,50) coordinate still in the source.

I tried changing axis and plot domain (and adding axis label):

\begin{axis}[ymin=0,ymax=1,xmin=0,xmax=1,thick,xlabel=x,ylabel=y]

and:

\addplot+[domain=0:1,...

This does not work for this type of plots. However this is work for other plots (e.g. function plots). How can I get this working?

enter image description here enter image description here


\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[black,const plot,mark=none]
coordinates
{(0,0.1)    (0.1,0.15)  (0.2,0.5)   (0.3,0.62)
 (0.4,0.56) (0.5,0.58)  (0.6,0.65)  (0.7,0.6)
 (0.8,0.58) (0.9,0.55)  (1,0.52) (1000,50) };
\end{axis}
\end{tikzpicture}
\end{document}
1

When setting xmin=0, xmax=1 in your example, I get a dimension too large error. This happens because the point 1000,50 is still processed, even though it lies outside the visible axis domain, and causes an overflow error. To fix this, set restrict x to domain=0:1. That key specifies that points with x coordinates outside the specified range are filtered out without any further processing:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=1, restrict x to domain=0:1]
\addplot+[black,const plot,mark=none]
coordinates
{(0,0.1)    (0.1,0.15)  (0.2,0.5)   (0.3,0.62)
 (0.4,0.56) (0.5,0.58)  (0.6,0.65)  (0.7,0.6)
 (0.8,0.58) (0.9,0.55)  (1,0.52) (1000,50) };
\end{axis}
\end{tikzpicture}
\end{document}

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.