我正在尝试使用 PGFPlots 重现此图中最底部的图表关联:
以下是我的最佳尝试:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ytick={1,...,5},
yticklabels={Barnes-Jewish,UCLA,UC San Francisco,John Hopkins,UCNI},
xbar,
title=Number of Verifications in 14 Specialty Areas of Neurological Care,
nodes near coords, nodes near coords align={horizontal}]
\addplot coordinates {
(13,5)
(10,4)
(9,3)
(9,2)
(2,1)
};
\end{axis}
\end{tikzpicture}
\end{document}
输出是
在这个问题中我所关心的关键区别是,数据标签靠近图表中条形的末端,并且位于文本标签旁边。关联。如何将数据标签放在文本标签旁边?
答案1
你可以从中借用一些代码pgfplots:将“靠近坐标的节点”定位在栏的底部其作用相同,只是方向不同y
。
我唯一添加的新部分是
visualization depends on=x \as \rawx,
every node near coord/.append style={
shift={(axis direction cs:-\rawx+0.8,0)}}
以下是完整的 MWE
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ytick={1,...,5},
yticklabels={Barnes-Jewish,UCLA,UC San Francisco,John Hopkins,UCNI},
xbar,
title=Number of Verifications in 14 Specialty Areas of Neurological Care,
nodes near coords, nodes near coords align={horizontal},
% begin new bit
visualization depends on=x \as \rawx,
every node near coord/.append style={
shift={(axis direction cs:-\rawx+0.8,0)}}
% end new bit
]
\addplot table {
x y
13 5
10 4
9 3
9 2
2 1
};
\end{axis}
\end{tikzpicture}
\end{document}