TransWikia.com

Dashed line as a mark in pgfplots

TeX - LaTeX Asked on December 1, 2020

I am trying to turn some markers into a dashed line in this diagram. However, I can only change them all at once. I need the "a", "b" and "c" to remain as a solid line, and turn "d" and "e" into a dashed line. It would be nice to label the separation between "d" and "e" with a curly bracket as shown below. How can I do that?

Code:

documentclass{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.15}
begin{document}
begin{tikzpicture}
 begin{axis}[
   every axis plot post/.style={mark=-,thick,mark size=10mm},
   xtick style={draw=none},
   xticklabels={,,},
   xmin=-0.9,
   xmax=1.1,
   ymin=14.5,
   ymax=19.5,
   cycle list name=black white,
   only marks, 
   x=2cm, y=1cm,
   every node near coord/.append style={font=small,yshift=-2.5mm,xshift=myshift}
 ]
addplot [nodes near coords={labelz},
visualization depends on={value thisrowno{2}aslabelz},visualization depends on={value thisrowno{3}asmyshift}] 
table[header=false] {
0 15.152 a 15mm
0 18.182 b 15mm
0 18.868 c 15mm
0 18.943 d -15mm
0 18.107 e -15mm
};
end{axis}
end{tikzpicture}
end{document}

Output:

enter image description here

Expected result:

enter image description here

One Answer

I managed to do this, not sure if it's the best solution:

documentclass{standalone}
usepackage{pgfplots}
usepackage{tikz}
usetikzlibrary{decorations.pathreplacing}
pgfplotsset{compat=1.15}
begin{document}
begin{tikzpicture}
 begin{axis}[
   xtick style={draw=none},
   xticklabels={,,},
   xmin=-0.9,
   xmax=1.1,
   ymin=14.5,
   ymax=19.5,
   cycle list name=black white,
   only marks, 
   x=2cm, y=1cm,
   every node near coord/.append style={font=small,yshift=-2.5mm,xshift=myshift}
 ]
addplot [mark=-,thick,mark size=10mm,nodes near coords={labelz},
visualization depends on={value thisrowno{2}aslabelz},visualization depends on={value thisrowno{3}asmyshift}] 
table[header=false] {
0 15.152 a 15mm
0 18.182 b 15mm
0 18.868 c 15mm
};
addplot [mark=-,thick,dashed,mark size=10mm,nodes near coords={labelz},
visualization depends on={value thisrowno{2}aslabelz},visualization depends on={value thisrowno{3}asmyshift}] 
table[header=false] {
0 18.943 {} -15mm
0 18.107 {} -15mm
};
draw [decorate,decoration={brace,mirror}]
(-0.55,18.943) -- (-0.55,18.107) node [midway,xshift=-5mm] {d};
end{axis}
end{tikzpicture}
end{document}

enter image description here

Answered by Rodrigo on December 1, 2020

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