1

How can I replace the dot with a comma in x coords?

enter image description here

    \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}

Thanks

  • 1
    Welcome to TeX.SE. To be able to answer your question effectively we need to see the code that you used to get your current chart. Can you edit your question to add the code? This should be in the form of a complete document, with the documentclass, packages you use for this chart, maybe \tikzset commands etc., such that when somebody runs your code there are no errors and the output is the same as in your screenshot. – Marijn May 21 '21 at 09:18

1 Answers1

0

This is very similar to Pgfplots: Labels from data table not working as expected. The idea is to plot the rows sequentially using the row index instead of the symbolic x coords, with the y values from the second column, as follows:

\addplot table[x expr=\coordindex,y index=1] {\data};

For the tick labels you use the first column:

xticklabels from table={\data}{0},

Now you only need to specify the labels once, and you can use a comma without getting errors about the symbolic coords.

MWE:

\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}

Result:

enter image description here

Marijn
  • 37,699