我正在尝试将这个图中的某些标记变成虚线。但是,我只能一次更改它们。我需要“a”、“b”和“c”保持为实线,并将“d”和“e”变成虚线。最好用花括号标记“d”和“e”之间的分隔,如下所示。我该怎么做?
代码:
\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}\as\labelz},visualization depends on={value \thisrowno{3}\as\myshift}]
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}
输出:
预期结果:
答案1
我设法做到了这一点,但不确定这是否是最好的解决方案:
\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}\as\labelz},visualization depends on={value \thisrowno{3}\as\myshift}]
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}\as\labelz},visualization depends on={value \thisrowno{3}\as\myshift}]
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}