I use tikz package for graph plotting. I have piecewise function enter image description here ,

which set as array of values in text file.

How I can plot given function this way?

  • 1
    Use pgffplots table input. If smoothing, put blank lines at the transitions, and possibly double up the inflection points (t=0.35 and t=0.55) Jul 1, 2019 at 20:05
  • you can plot 3 times with 3 different domains
    – Black Mild
    Jul 2, 2019 at 4:21

1 Answer 1


Of course you can declare such a function and plot it with plain TikZ. (I do agree with John Kormylo that pgfplots may be more appropriate, but there you can just plot the function, there is no need for tables.) With samples at you can control the points where the function is evaluated. In the domains in which the function is linear, there is no need to have more than 2 samples.

\begin{tikzpicture}[declare function={f(\x)=ifthenelse(\x<0.35,-\x,
 \draw[-stealth] (0,0) -- (1.2,0) node[below left]{$t$};
 \draw[-stealth] (0,-1) -- (0,1) node[below left]{$f(t)$};
 \draw[blue] plot[variable=\x,domain=0:1,samples
 at={0,0.3499,0.35,0.36,0.37,...,0.55,0.55001,1}] ({\x},{f(\x)});

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .