TransWikia.com

How to draw a contiguous line where each segment starts where previous ended

TeX - LaTeX Asked by me-- on April 10, 2021

Maybe I’m not thinking about this right, but I would like to draw a line from a set of input data. Each data entry provides a single point in that line. If the line was "static", I’d just do something like:

draw (0,100) -- (50,99) -- (150,80) -- (200,90) -- (250,65);

But I would like the y values to come from a data list. I was hoping I could do something like:

draw (0,100) -- (50,99);
draw -- (150,80);
% etc

The idea being that the second draw command uses (50,99) as its starting coordinate. That way I could use a foreach or something. But this doesn’t work.

Am I missing some clean way to do this?

2 Answers

I am not sure if I understand your question completly. Does this look like what you want to achieve?

documentclass{standalone}
usepackage{tikz}

begin{document}
begin{tikzpicture}
    
    
    draw[line width=2mm, red ] (0,100)
    foreach x/y in {50/99,100/98,150/80,200/90,250/65}
    {-- (x,y)};
    
end{tikzpicture}

end{document}

enter image description here

Correct answer by Roland on April 10, 2021

Two more options. First one uses foreach inside draw command and second one uses plot coordinates command.

documentclass[tikz, border=5mm]{standalone}

begin{document}
begin{tikzpicture}
draw[red, line width=2mm] (0,100) foreach i in {(50,99),(150,80),(200,90),(250,65)}{--i};
end{tikzpicture} 

begin{tikzpicture}
draw[blue, line width=2mm] plot coordinates {(0,100) (50,99) (150,80) (200,90) (250,65)};
end{tikzpicture} 
end{document}

enter image description here

Answered by Ignasi on April 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP