# Can I connect the end of an \addplot to the beginning of the next \addplot?

I'm using pgfplots to plot an implicit equation, but I'm running around using gnuplot by parametrizing the curve instead. The down side is that my parametrization necessarily comes in curve segments. There are certain places in the plot where the parametrized segments should meet up, but don't quite, and leave a little white space. Is there an option I could pass to an \addplot, or some other tikz tool, so that the last sampled point form the previous \addplot is used as a 0th sample point for the next \addplot?

Here is a MWE:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[variable=v,samples=100]
%There is a white gap between these two curves that I'd like to automatically bridge
\end{axis}
\end{tikzpicture}

\end{document}

• You can put domain=2.3499859792:2.3499859793 in the second \addplot – jpayansomet May 6 '15 at 6:10
• @jpayansomet This is just an minimal working example. I am looking for a universal way to bridge these curve segments, without refining the domains further. There are too many segments in my actual project to investigate exploring all of the domains like this. – alex.jordan May 6 '15 at 6:13
• Then I don't know the answer. – jpayansomet May 6 '15 at 6:16
• Are you OK with using shorten key? Anyway, I am posting an answer. Please drop comments. – user11232 May 6 '15 at 8:19
• Use a piecewise function : tex.stackexchange.com/questions/132476/… – percusse May 6 '15 at 8:31

Here is an option with shorten key. The amount by which to shorten need to be carefully chosen so as to make the curve look continuous. Here you need not change the domains.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[variable=v,samples=100]
%There is a white gap between these two curves that I'd like to automatically bridge
\end{axis}
\end{tikzpicture}

\end{document}


• Thanks for this answer. I decided not to go this route because I didn't want to take care about how much to (anti)-shorten with each such connection. – alex.jordan May 7 '15 at 0:06

I ended up declaring functions for the paramterization, dialing back the domain a bit to help ensure I'm not bumping up against machine rounding error, and then just plotting the endpoints separately using the named functions, with a simplie connecting line.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[
declare function={
c(\x)= cos(\x^2*180/3.14159265359);
sm(\x)=sqrt(4-\x^2*c(\x));
m(\x)= 2+sm(\x);
n(\x)= 2-sm(\x);
f(\x)= \x^2/m(\x);
g(\x)= m(\x)/c(\x);
}
]
\begin{axis}[variable=v,samples=100]
\end{axis}
\end{tikzpicture}

\end{document}


This is more comment than answer. But it is to long to be placed in field for comments ... so, I decided to wrote it as an answer even it hasn't much common with LaTeX.

If I understand your question correctly, you like to draw diagram of segment of two different functions, which has common domain of independent variable v and cross each other. Segment of the first function is (for example) on the left side of cross point, and second is on the right side.

To determine of cross point you need to consider how accurate you can determine it. All numerical methods, particulary (La)TeX (which is not designed for solve mathematical/numerical problems) has (so called) numerical noise, so you can expect that value of variable v will give different position of cross point for each function. Another problem is nature of your graph. Its points in diagram are not determined in form (x,y) = (v,f(v)) but in implicit form (x,y) = (f_1(v),f_2(v)). This causes additional problem in accuracy to determining of v.

How to overcome this problems? One solution is proposed in answer of Harish Kumar. He actually suggest that in vicinity of cross or common point of both function you draw fake graphs of them. This approach hide actual form of diagrams (for example discontinuity of functions in this point) in vicinity of this point. To my opinion, from mathematical point of view it is more correct to left graph as it is and eventually add comment/explanation why the graph here has gap; or extent of domain of independent variable v for amount, that the crossing of function (if exist) is visible.

By the way, it seems that your function haven't common point. So, the gap should be in graph. And, are you sure, that your conversion from radians to degrees is correct/consistent?

An alternative to defining a piece-wise function is to define your function such that you can use it both for plotting and computing individual values, as given in the answer to this question: Consistently specify a Function and use it for computation and plotting

Here's a MWE, where I've defined 2 functions A and B, plotted them over separate domains, and then calculated coordinates to add 2 straight lines. Note that you can use the functions directly with braces (method 1) or set macros to store coordinate values (method 2).

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}%

\def\myFuncA(#1){(#1)^3}%
\def\myFuncB(#1){20*exp(-1*#1)}%

\begin{document}
\begin{tikzpicture}
\begin{axis}