Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to hide a part of a plot, possibly by specifying the interval numerically?

I have a plot with xmin, xmax, ymin and ymax defined and I need to move it from the y axis without using enlarge x limits.

In this case, I would like to keep everything as it is and just hide the part of the plot between -0.5 and 0 on the x axis.

Minimal working example:

\documentclass[border=2pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xmin=-0.5,
    xmax=5.5,
    ymin=-1.54,
    ymax=16.96,
]

\addplot[style=loosely dashed, thick] gnuplot{0.261*x+8.073};

\end{axis}
\end{tikzpicture}
\end{document}

The aim is to correctly align two axes, one of them with symbolic coordinates and automatic padding, hence unable to plot this function. Should someone think of covering it by using an overlaying shape, it is unacceptable because the background varies in colour.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You can set the range over which the function is evaluated using the domain=<min>:<max> key.

\documentclass[border=2pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xmin=-0.5,
    xmax=5.5,
    ymin=-1.54,
    ymax=16.96,
    domain=0:5.5
]

\addplot[style=loosely dashed, thick, samples=2] gnuplot{0.261*x+8.073};

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
I have specified the domain before and yet I did not think of it somehow. :-) Thank you very much! –  Harold Cavendish Apr 17 '12 at 18:57
add comment

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.