我怎样才能将 x 坐标中的点替换为逗号?
\documentclass[border=10pt, 12pt]{standalone}
\usepackage{pgfplotstable}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{times}
\date{September 2020}
\begin{document}
\pgfplotstableread[col sep=semicolon,header=false]{
$(-\infty.25)$;60
$\langle25.30)$;105
$\langle30.35)$; 138
$\langle35.40)$; 126
$\langle40.45)$; 217
$\langle45.50)$; 185
$\langle50.\infty)$; 150
}\data
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
ybar=0pt,
bar width=25pt,
xlabel={Věková skupina $j$\,[věk]},
ylabel={Nálet [h]},
width=13cm,
height=8cm,
enlarge x limits=0.15,
symbolic x coords={$(-\infty.25)$, $\langle25.30)$, $\langle30.35)$, $\langle35.40)$, $\langle40.45)$, $\langle45.50)$, $\langle50.\infty)$},
xtick=data, bar width=30pt,nodes near coords,
compat=newest, scaled y ticks={base 10:0},
]
\addplot table {\data};
\end{axis}
\end{tikzpicture}
\end{document}
谢谢
答案1
这非常类似于Pgfplots:数据表中的标签未按预期工作这个想法是使用行索引而不是符号 x 坐标按顺序绘制行,并使用第二列的 y 值,如下所示:
\addplot table[x expr=\coordindex,y index=1] {\data};
对于刻度标签,使用第一列:
xticklabels from table={\data}{0},
现在您只需指定一次标签,并且可以使用逗号而不会出现有关符号坐标的错误。
梅威瑟:
\documentclass[border=10pt, 12pt]{standalone}
\usepackage{pgfplotstable}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{times}
\date{September 2020}
\begin{document}
\pgfplotstableread[col sep=semicolon,header=false]{
$(-\infty,25)$;60
$\langle25,30)$;105
$\langle30,35)$; 138
$\langle35,40)$; 126
$\langle40,45)$; 217
$\langle45,50)$; 185
$\langle50,\infty)$; 150
}\data
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
ybar=0pt,
bar width=25pt,
xlabel={Věková skupina $j$\,[věk]},
ylabel={Nálet [h]},
width=13cm,
height=8cm,
enlarge x limits=0.15,
xticklabels from table={\data}{0},
xtick=data, bar width=30pt,nodes near coords,
compat=newest, scaled y ticks={base 10:0},
]
\addplot table[x expr=\coordindex,y index=1] {\data};
\end{axis}
\end{tikzpicture}
\end{document}
结果: