我有一个条形图,在条形旁边打印数字。但是,由于文本的颜色问题,文本的可读性不是很好。
因此我想知道如何修改它的风格。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\begin{document}
\pgfplotstableread[header=false, col sep=comma]{ % Read data table.
% First row doesn't have column names, hence the "header=false"
1, first item
5, second item
}\datatable
\begin{tikzpicture}
\begin{axis}[
,xbar
,bar width=2ex, y=3ex
,nodes near coords
,nodes near coords align={horizontal}
% my approach:
,every node near coords/.append style={color=red}
%%
,enlarge y limits={abs=0.75}
,ytick={data} % (\empty,data,{coordinate list})
,yticklabels from table={\datatable}{1}
]
\addplot table [
y expr=-\coordindex, % Use negative coordinate index as y coordinate
x index=0 % Use first column as x coordinate
] {\datatable};
\end{axis}
\end{tikzpicture}
\end{document}