我正在尝试使用 PGFPLOTS 创建图表,例如这:
这是我的数据文件:
SN STAR PLANET R RU RL
1 51 Peg b 0.0521068 0.000868447 0.000868447
2 55 Cnc b 0.113377 0.00188961 0.00188961
2 55 Cnc c 0.237305 0.00395515 0.00395515
2 55 Cnc d 5.47467 0.0939312 0.0939312
2 55 Cnc e 0.0154393 0.000257321 0.000257321
2 55 Cnc f 0.773567 0.0129169 0.0129169
3 6 Lyn b 2.18639 0.055765 0.055765
4 61 Vir b 0.05006 0.000834347 0.000834347
4 61 Vir c 0.216926 0.00361774 0.00361774
4 61 Vir d 0.474527 0.00803427 0.00803427
5 7 CMa b 1.80264 0.0641495 0.0641495
6 70 Vir b 0.483601 0.00806003 0.00806003
7 75 Cet b 1.97678 0.0555905 0.0555905
8 81 Cet b 2.28088 0.0928283 0.0928283
这是我的代码:
\begin{tikzpicture}
\begin{axis}[
title=Fig. 1: Exoplanets data and model prediction,
xmode=log, xlabel={Semi-major axis (AU)},
visualization depends on={value \thisrow{PLANET} \as \labelplanet},
nodes near coords={\labelplanet},
flexible yticklabels from table={Exoplanets/test.dat}{STAR}{col sep=tab}, ytick=data, y dir=reverse,
]
\addplot+[mark=*, only marks, mark size=0.33, error bars/.cd, x dir=both, x explicit]
table[x=R,x error plus=RU,x error minus=RL,y=SN,col sep=tab] {Exoplanets/test.dat};
\end{axis}
\end{tikzpicture}
问题是,第 2 行没有被标记为55 数控在第 3 行中六 林恩,我得到 5 行(#2-#6)标签55 数控。
显然,该错误与我从另一篇文章中复制来创建标签的代码不兼容:
\pgfplotstableread[col sep=tab]{Exoplanets/test.dat}\datatable
\makeatletter
\pgfplotsset{
/pgfplots/flexible yticklabels from table/.code n args={3}{%
\pgfplotstableread[#3]{#1}\coordinate@table
\pgfplotstablegetcolumn{#2}\of{\coordinate@table}\to\pgfplots@yticklabels
\let\pgfplots@yticklabel=\pgfplots@user@ticklabel@list@y
}
}
\makeatother
但我不知道这一切意味着什么。有人能帮我吗?
编辑:这是 LaRiFaRi 请求的可编译代码。
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=16cm, compat=1.12}
\pgfplotstableread[col sep=tab]{Exoplanets/test.dat}\datatable
\makeatletter
\pgfplotsset{
/pgfplots/flexible yticklabels from table/.code n args={3}{%
\pgfplotstableread[#3]{#1}\coordinate@table
\pgfplotstablegetcolumn{#2}\of{\coordinate@table}\to\pgfplots@yticklabels
\let\pgfplots@yticklabel=\pgfplots@user@ticklabel@list@y
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title=Fig. 1: Exoplanets data and model prediction,
xmode=log, xlabel={Semi-major axis (AU)},
visualization depends on={value \thisrow{PLANET} \as \labelplanet},
nodes near coords={\labelplanet},
flexible yticklabels from table={Exoplanets/test.dat}{STAR}{col sep=tab}, ytick=data, y dir=reverse,
]
\addplot+[mark=*, only marks, mark size=0.33, error bars/.cd, x dir=both, x explicit]
table[x=R,x error plus=RU,x error minus=RL,y=SN,col sep=tab] {Exoplanets/test.dat};
\end{axis}
\end{tikzpicture}
\end{document}