Is there any way to plot a continuous line with pgfplot/tikz using only 2 points (i.e. it will extend past those points on its own) within the domain I specify?
[Tex/LaTex] Plot Continuous Line With 2 Points
tikz-pgf
Related Solutions
Choosing a good line cap
(like butt
) can help... but it's not sufficient (look at first blue line). Using a clip
region is the solution (like with my second scope
).
\documentclass[tikz]{standalone}
\newcommand\redpt[1]{\fill[red] (#1) circle[radius=1mm];}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\draw[help lines] (-5,0) grid (0,5);
\draw[line width=5mm,line cap=round] (-5,4) -- (0,4);
\redpt{-5,4}
\draw[line width=5mm,line cap=rect] (-5,3) -- (0,3);
\redpt{-5,3}
\draw[line width=5mm,line cap=butt] (-5,2) -- (0,2);
\redpt{-5,2}
\draw[line width=5mm,line cap =butt,blue] (-5,1) -- (0,3.5);
\redpt{-5,1}
\end{scope}
\begin{scope}[shift={(0,-5.2)}]
\draw[help lines] (-5,0) grid (0,5);
\clip (-5,0) rectangle (0,5);
\draw[line width=5mm,line cap=round] (-5,4) -- (0,4);
\redpt{-5,4}
\draw[line width=5mm,line cap=rect] (-5,3) -- (0,3);
\redpt{-5,3}
\draw[line width=5mm,line cap=butt] (-5,2) -- (0,2);
\redpt{-5,2}
\draw[line width=5mm,line cap =butt,blue] (-5,1) -- (0,3.5);
\redpt{-5,1}
\end{scope}
\end{tikzpicture}
\end{document}
I am not sure if this is what you want, but I would suggest you to use the pgfplots
package (internally uses TikZ); a little example (the solid and hollow dot styles are borrowed from a comment by cmhughes):
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\pgfplotsset{soldot/.style={color=blue,only marks,mark=*}} \pgfplotsset{holdot/.style={color=blue,fill=white,only marks,mark=*}}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[domain=0:4,blue] {x*x};
\addplot[domain=4:6,blue] {x};
\addplot[domain=6:10,blue] {-5};
\draw[dotted] (axis cs:4,16) -- (axis cs:4,4);
\draw[dotted] (axis cs:6,6) -- (axis cs:6,-5);
\addplot[holdot] coordinates{(0,0)(4,4)(6,-5)};
\addplot[soldot] coordinates{(4,16)(6,6)(10,-5)};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
You can use
shorten
with a negative length to extend the edge.