How to use a mathematical expression as xticklabel












2















I have prepared a code including some data resulting in a bar plot. I want to use a mathematical expression as xticklabels but my code does not work. How can I figure this point out?



Here is my code:



documentclass[tikz,border=3.15mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16,width=15.5cm}
usepackage{comment}



begin{document}
begin{tikzpicture}
begin{axis}[
ybar,
xticklabels={
{$ 10_g to 8_g $}, {$ 8_g to 6_g $}, {$ 6_g to 4_g $}, {$ 4_g to 2_g $},
{$ 8_g to 8gamma $}, {$ 6_g to 6gamma $}, {$ 4_g to 4gamma $}, { $ 2_g to 2gamma $},
{$ 7_gamma to 8_g $}, {$ 5_gamma to 6_g $}, {$ 3_gamma to 4_g $},
{$ 8_gamma to 6_gamma $}, {$ 6_gamma to 4_gamma $}, {$ 4_gamma to 2_gamma $},
{$ 7_gamma to 5_gamma $}, {$ 5_gamma to 3_gamma $},
{$ 7_gamma to 6_gamma $}, {$ 5_gamma to 4_gamma $}, {$ 3_gamma to 2_gamma $}
},
x tick label style={rotate=90},
enlarge x limits=0.1,
legend style={at={(0.85,1)},
anchor=north,legend columns=-1},
bar width = 0.2 cm,
symbolic x coords={10gto8g, 8gto6g, 6gto4g, 4gto2g, 8gto8gamma, 6gto6gamma, 4gto4gamma, 2gto2gamma, 7gammato8g, 5gammato6g, 3gammato4g, 8gammato6gamma, 6gammato4gamma, 4gammato2gamma, 7gammato5gamma, 5gammato3gamma, 7gammato6gamma, 5gammato4gamma, 3gammato2gamma},
xtick=data,
nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
nodes near coords align={vertical},
nodes near coords style={rotate=90,anchor=west,font=small}
]


addplot+[bar shift = -0.25cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };


addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };

addplot+[bar shift = 0.25cm] coordinates coordinates {(10gto8g,2.967) (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313) (3gammato2gamma,2.171) };

end{axis}
end{tikzpicture}




end{document}


Many thanks.










share|improve this question





























    2















    I have prepared a code including some data resulting in a bar plot. I want to use a mathematical expression as xticklabels but my code does not work. How can I figure this point out?



    Here is my code:



    documentclass[tikz,border=3.15mm]{standalone}
    usepackage{pgfplots}
    pgfplotsset{compat=1.16,width=15.5cm}
    usepackage{comment}



    begin{document}
    begin{tikzpicture}
    begin{axis}[
    ybar,
    xticklabels={
    {$ 10_g to 8_g $}, {$ 8_g to 6_g $}, {$ 6_g to 4_g $}, {$ 4_g to 2_g $},
    {$ 8_g to 8gamma $}, {$ 6_g to 6gamma $}, {$ 4_g to 4gamma $}, { $ 2_g to 2gamma $},
    {$ 7_gamma to 8_g $}, {$ 5_gamma to 6_g $}, {$ 3_gamma to 4_g $},
    {$ 8_gamma to 6_gamma $}, {$ 6_gamma to 4_gamma $}, {$ 4_gamma to 2_gamma $},
    {$ 7_gamma to 5_gamma $}, {$ 5_gamma to 3_gamma $},
    {$ 7_gamma to 6_gamma $}, {$ 5_gamma to 4_gamma $}, {$ 3_gamma to 2_gamma $}
    },
    x tick label style={rotate=90},
    enlarge x limits=0.1,
    legend style={at={(0.85,1)},
    anchor=north,legend columns=-1},
    bar width = 0.2 cm,
    symbolic x coords={10gto8g, 8gto6g, 6gto4g, 4gto2g, 8gto8gamma, 6gto6gamma, 4gto4gamma, 2gto2gamma, 7gammato8g, 5gammato6g, 3gammato4g, 8gammato6gamma, 6gammato4gamma, 4gammato2gamma, 7gammato5gamma, 5gammato3gamma, 7gammato6gamma, 5gammato4gamma, 3gammato2gamma},
    xtick=data,
    nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
    nodes near coords align={vertical},
    nodes near coords style={rotate=90,anchor=west,font=small}
    ]


    addplot+[bar shift = -0.25cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };


    addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };

    addplot+[bar shift = 0.25cm] coordinates coordinates {(10gto8g,2.967) (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313) (3gammato2gamma,2.171) };

    end{axis}
    end{tikzpicture}




    end{document}


    Many thanks.










    share|improve this question



























      2












      2








      2








      I have prepared a code including some data resulting in a bar plot. I want to use a mathematical expression as xticklabels but my code does not work. How can I figure this point out?



      Here is my code:



      documentclass[tikz,border=3.15mm]{standalone}
      usepackage{pgfplots}
      pgfplotsset{compat=1.16,width=15.5cm}
      usepackage{comment}



      begin{document}
      begin{tikzpicture}
      begin{axis}[
      ybar,
      xticklabels={
      {$ 10_g to 8_g $}, {$ 8_g to 6_g $}, {$ 6_g to 4_g $}, {$ 4_g to 2_g $},
      {$ 8_g to 8gamma $}, {$ 6_g to 6gamma $}, {$ 4_g to 4gamma $}, { $ 2_g to 2gamma $},
      {$ 7_gamma to 8_g $}, {$ 5_gamma to 6_g $}, {$ 3_gamma to 4_g $},
      {$ 8_gamma to 6_gamma $}, {$ 6_gamma to 4_gamma $}, {$ 4_gamma to 2_gamma $},
      {$ 7_gamma to 5_gamma $}, {$ 5_gamma to 3_gamma $},
      {$ 7_gamma to 6_gamma $}, {$ 5_gamma to 4_gamma $}, {$ 3_gamma to 2_gamma $}
      },
      x tick label style={rotate=90},
      enlarge x limits=0.1,
      legend style={at={(0.85,1)},
      anchor=north,legend columns=-1},
      bar width = 0.2 cm,
      symbolic x coords={10gto8g, 8gto6g, 6gto4g, 4gto2g, 8gto8gamma, 6gto6gamma, 4gto4gamma, 2gto2gamma, 7gammato8g, 5gammato6g, 3gammato4g, 8gammato6gamma, 6gammato4gamma, 4gammato2gamma, 7gammato5gamma, 5gammato3gamma, 7gammato6gamma, 5gammato4gamma, 3gammato2gamma},
      xtick=data,
      nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
      nodes near coords align={vertical},
      nodes near coords style={rotate=90,anchor=west,font=small}
      ]


      addplot+[bar shift = -0.25cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };


      addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };

      addplot+[bar shift = 0.25cm] coordinates coordinates {(10gto8g,2.967) (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313) (3gammato2gamma,2.171) };

      end{axis}
      end{tikzpicture}




      end{document}


      Many thanks.










      share|improve this question
















      I have prepared a code including some data resulting in a bar plot. I want to use a mathematical expression as xticklabels but my code does not work. How can I figure this point out?



      Here is my code:



      documentclass[tikz,border=3.15mm]{standalone}
      usepackage{pgfplots}
      pgfplotsset{compat=1.16,width=15.5cm}
      usepackage{comment}



      begin{document}
      begin{tikzpicture}
      begin{axis}[
      ybar,
      xticklabels={
      {$ 10_g to 8_g $}, {$ 8_g to 6_g $}, {$ 6_g to 4_g $}, {$ 4_g to 2_g $},
      {$ 8_g to 8gamma $}, {$ 6_g to 6gamma $}, {$ 4_g to 4gamma $}, { $ 2_g to 2gamma $},
      {$ 7_gamma to 8_g $}, {$ 5_gamma to 6_g $}, {$ 3_gamma to 4_g $},
      {$ 8_gamma to 6_gamma $}, {$ 6_gamma to 4_gamma $}, {$ 4_gamma to 2_gamma $},
      {$ 7_gamma to 5_gamma $}, {$ 5_gamma to 3_gamma $},
      {$ 7_gamma to 6_gamma $}, {$ 5_gamma to 4_gamma $}, {$ 3_gamma to 2_gamma $}
      },
      x tick label style={rotate=90},
      enlarge x limits=0.1,
      legend style={at={(0.85,1)},
      anchor=north,legend columns=-1},
      bar width = 0.2 cm,
      symbolic x coords={10gto8g, 8gto6g, 6gto4g, 4gto2g, 8gto8gamma, 6gto6gamma, 4gto4gamma, 2gto2gamma, 7gammato8g, 5gammato6g, 3gammato4g, 8gammato6gamma, 6gammato4gamma, 4gammato2gamma, 7gammato5gamma, 5gammato3gamma, 7gammato6gamma, 5gammato4gamma, 3gammato2gamma},
      xtick=data,
      nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
      nodes near coords align={vertical},
      nodes near coords style={rotate=90,anchor=west,font=small}
      ]


      addplot+[bar shift = -0.25cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };


      addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };

      addplot+[bar shift = 0.25cm] coordinates coordinates {(10gto8g,2.967) (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313) (3gammato2gamma,2.171) };

      end{axis}
      end{tikzpicture}




      end{document}


      Many thanks.







      tikz-pgf pgfplots plot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 4 at 9:46









      Bernard

      173k776204




      173k776204










      asked Mar 4 at 4:51









      Hadi SobhaniHadi Sobhani

      27016




      27016






















          3 Answers
          3






          active

          oldest

          votes


















          2














          There were two issues:




          1. in the last plot you had coordinates twice.

          2. for some reason, pgfplots does not like a to. The deeper reason can be presumably found in pgfplots.code.tex, where to is used in many macros.


          I acknowledge that John Kormylo beat me by seconds (while I was typing the explanation).





          documentclass[tikz,border=3.15mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16,width=17.5cm}
          usepackage{comment}



          begin{document}
          begin{tikzpicture}
          begin{axis}[ybar,
          x tick label style={rotate=90},
          enlarge x limits=0.04,
          legend style={at={(0.85,1)},
          anchor=north,legend columns=-1},
          bar width=0.2cm,
          xtick=data,
          symbolic x coords={10gto8g,8gto6g,6gto4g,4gto2g,8gto8gamma,6gto6gamma,4gto4gamma,2gto2gamma,7gammato8g,5gammato6g,3gammato4g,8gammato6gamma,6gammato4gamma,4gammato2gamma,7gammato5gamma,5gammato3gamma,7gammato6gamma,5gammato4gamma,3gammato2gamma},
          xticklabels={
          {$10_grightarrow8_g$},{$8_grightarrow6_g$},{$6_grightarrow4_g$},{$4_grightarrow2_g$},
          {$8_grightarrow8gamma$},{$6_grightarrow6gamma$},{$4_grightarrow4gamma$},{$2_grightarrow2gamma$},
          {$7_gammarightarrow8_g$},{$5_gammarightarrow6_g$},{$3_gammarightarrow4_g$},
          {$8_gammarightarrow6_gamma$},{$6_gammarightarrow4_gamma$},{$4_gammarightarrow2_gamma$},
          {$7_gammarightarrow5_gamma$},{$5_gammarightarrow3_gamma$},
          {$7_gammarightarrow6_gamma$},{$5_gammarightarrow4_gamma$},
          {$3_gammarightarrow2_gamma$}
          },
          nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
          nodes near coords align={vertical},
          nodes near coords style={rotate=90,anchor=west,font=small}
          ]


          addplot+[bar shift = -0.25cm]
          coordinates {(10gto8g,0)
          (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0)
          };
          %
          %
          addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };
          %
          % % Z5 coordinate was in twice
          addplot+[bar shift = 0.25cm] coordinates {(10gto8g,2.967)
          (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313)
          (3gammato2gamma,2.171)
          };

          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer


























          • Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

            – Hadi Sobhani
            Mar 4 at 6:01











          • @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

            – marmot
            Mar 4 at 6:06



















          4














          Tikz redefines to. Use rightarrow instead. Also, it seems that symbolic x coordinates and xticklables are incompatible.



          documentclass[tikz,border=3.15mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16,width=15.5cm}
          usepackage{comment}

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ybar,
          xtick=data,
          x tick label style={rotate=90},
          enlarge x limits=0.1,
          legend style={at={(0.85,1)},
          anchor=north,legend columns=-1},
          bar width = 0.2 cm,
          nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
          nodes near coords align={vertical},
          nodes near coords style={rotate=90,anchor=west,font=small},
          xticklabels={
          {$ 10_g rightarrow 8_g $}, {$ 8_g rightarrow 6_g $}, {$ 6_g rightarrow 4_g $}, {$ 4_g rightarrow 2_g $},
          {$ 8_g rightarrow 8gamma $}, {$ 6_g rightarrow 6gamma $}, {$ 4_g rightarrow 4gamma $}, {$ 2_g rightarrow 2gamma $},
          {$ 7_gamma rightarrow 8_g $}, {$ 5_gamma rightarrow 6_g $}, {$ 3_gamma rightarrow 4_g $},
          {$ 8_gamma rightarrow 6_gamma $}, {$ 6_gamma rightarrow 4_gamma $}, {$ 4_gamma rightarrow 2_gamma $},
          {$ 7_gamma rightarrow 5_gamma $}, {$ 5_gamma rightarrow 3_gamma $},
          {$ 7_gamma rightarrow 6_gamma $}, {$ 5_gamma rightarrow 4_gamma $}, {$ 3_gamma rightarrow 2_gamma $}
          },
          ]

          addplot+[bar shift = -0.25cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

          addplot+[bar shift = 0cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

          % Z5
          addplot+[bar shift = 0.25cm] coordinates {(1,2.967) (2,2.635) (3,2.203) (4,1.590) (5,0.1290) (6,0.1976) (7,0.3481) (8,1.620) (9,0.808) (10,0.972) (11,1.243) (12,1.590) (13,1.031) (14,0.736) (15,1.851) (16,1.235) (17,1.260) (18,1.313) (19,2.171) };

          end{axis}
          end{tikzpicture}

          end{document}


          demo





          It occurred to me that it might be better to record the data in table format.



          documentclass[tikz,border=3.15mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16,width=15.5cm}
          usepackage{pgfplotstable}

          newcommand{mylabels}{}% reserve global name

          begin{document}
          pgfplotstableread[col sep=comma, string type]{
          x, name, label, y1, y2, y3
          1, 10gto8g, $10_g rightarrow 8_g$, 0,0,2.967
          2, 8gto6g, $8_g rightarrow 6_g$, 0,0,2.635
          3, 6gto4g, $6_g rightarrow 4_g$, 0,0,2.203
          4, 4gto2g, $4_g rightarrow 2_g$, 0,0,1.590
          5, 8gto8gamma, $8_g rightarrow 8gamma$, 0,0,0.1290
          6, 6gto6gamma, $6_g rightarrow 6gamma$, 0,0,0.1976
          7, 4gto4gamma, $4_g rightarrow 4gamma$, 0,0,0.3481
          8, 2gto2gamma, $2_g rightarrow 2gamma$, 0,0,1.620
          9, 7gammato8g, $7_gamma rightarrow 8_g$, 0,0,0.808
          10, 5gammato6g, $5_gamma rightarrow 6_g$, 0,0,0.972
          11, 3gammato4g, $3_gamma rightarrow 4_g$, 0,0,1.243
          12, 8gammato6gamma, $8_gamma rightarrow 6_gamma$, 0,0,1.590
          13, 6gammato4gamma, $6_gamma rightarrow 4_gamma$, 0,0,1.031
          14, 4gammato2gamma, $4_gamma rightarrow 2_gamma$, 0,0,0.736
          15, 7gammato5gamma, $7_gamma rightarrow 5_gamma$, 0,0,1.851
          16, 5gammato3gamma, $5_gamma rightarrow 3_gamma$, 0,0,1.235
          17, 7gammato6gamma, $7_gamma rightarrow 6_gamma$, 0,0,1.260
          18, 5gammato4gamma, $5_gamma rightarrow 4_gamma$, 0,0,1.313
          19, 3gammato2gamma, $3_gamma rightarrow 2_gamma$, 0,0,2.171
          }mytable

          %pgfplotstabletypeset[string type]mytable% error check
          pgfplotstablegetelem{0}{label}ofmytable% put labels into macro mylabels
          xdefmylabels{pgfplotsretval}%
          foreach i in {1,2,...,18}{pgfplotstablegetelem{i}{label}ofmytable
          xdefmylabels{mylabels,pgfplotsretval}}%

          begin{tikzpicture}
          begin{axis}[
          ybar,
          xtick=data,
          x tick label style={rotate=90},
          enlarge x limits=0.1,
          legend style={at={(0.85,1)},
          anchor=north,legend columns=-1},
          bar width = 0.2 cm,
          nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
          nodes near coords align={vertical},
          nodes near coords style={rotate=90,anchor=west,font=small},
          xticklabels/.expand once=mylabels
          ]

          addplot+[bar shift = -0.25cm] table[x=x, y=y1] mytable;
          addplot+[bar shift = 0cm] table[x=x, y=y2] mytable;
          addplot+[bar shift = 0.25cm] table[x=x, y=y3] mytable;
          end{axis}
          end{tikzpicture}

          end{document}





          share|improve this answer

































            1














            with use of pgfplotstable you will not have problem with use of to math symbol. beside this code is simpler, a bit shorter and to my opinion more clear. based on my answer on your previous question, i rewrite your mwe to:



            documentclass[margin=3mm]{standalone}
            usepackage{pgfplotstable}
            pgfplotsset{compat=1.16}

            begin{document}
            begin{tikzpicture}
            pgfplotstableread{
            X Y1 Y2 Y3
            $10_gto 8_g$ 0 0 2.967
            $8_gto 6_g$ 0 0 2.635
            $6_gto 4_g$ 0 0 2.203
            $4_gto 2_g$ 0 0 1.590
            $8_gto 8gamma$ 0 0 0.1290
            $6_gto 6gamma$ 0 0 0.1976
            $4_gto 4gamma$ 0 0 0.3481
            $2_gto 2gamma$ 0 0 1.6204
            $8_gammato 6_gamma$ 0 0 1.590
            $6_gammato 4_gamma$ 0 0 1.031
            $4_gammato 2_gamma$ 0 0 0.736
            $8_gammato 6_gamma$ 0 0 1.590
            $6_gammato 4_gamma$ 0 0 1.031
            $4_gammato 2_gamma$ 0 0 0.736
            $7_gammato 5_gamma$ 0 0 1.851
            $5_gammato 3_gamma$ 0 0 1.235
            $7_gammato 6_gamma$ 0 0 1.260
            $5_gammato 4_gamma$ 0 0 1.313
            $3_gammato 2_gamma$ 0 0 2.171
            }mydata

            begin{axis}[width=160mm,
            enlarge x limits=0.04,
            enlarge y limits=0.01,
            legend style={legend columns=-1,
            % legend pos=north east,
            font=footnotesize,
            /tikz/every even column/.append style={column sep=2mm},
            anchor=north,
            at={(0.5,-0.12)},
            },
            ybar=0.4mm, % distance between bars (shift bar)
            bar width=1.8mm, % width of bars
            nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
            nodes near coords style={font=scriptsize, inner sep=2pt, rotate=90, anchor=west},
            nodes near coords align={vertical},
            ymin=0, ymax=3.5,
            ytick={0,0.5,...,3.5},
            %
            xtick=data,
            xticklabels from table = {mydata}{X},
            x tick label style={rotate=90, anchor=east},
            scale only axis,
            ]
            addplot table[x expr=coordindex,y index=1] {mydata};
            addplot table[x expr=coordindex,y index=2] {mydata};
            addplot table[x expr=coordindex,y index=3] {mydata};

            legend{used,understood,not understood}
            end{axis}
            end{tikzpicture}
            end{document}


            gives:



            enter image description here






            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "85"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477635%2fhow-to-use-a-mathematical-expression-as-xticklabel%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              There were two issues:




              1. in the last plot you had coordinates twice.

              2. for some reason, pgfplots does not like a to. The deeper reason can be presumably found in pgfplots.code.tex, where to is used in many macros.


              I acknowledge that John Kormylo beat me by seconds (while I was typing the explanation).





              documentclass[tikz,border=3.15mm]{standalone}
              usepackage{pgfplots}
              pgfplotsset{compat=1.16,width=17.5cm}
              usepackage{comment}



              begin{document}
              begin{tikzpicture}
              begin{axis}[ybar,
              x tick label style={rotate=90},
              enlarge x limits=0.04,
              legend style={at={(0.85,1)},
              anchor=north,legend columns=-1},
              bar width=0.2cm,
              xtick=data,
              symbolic x coords={10gto8g,8gto6g,6gto4g,4gto2g,8gto8gamma,6gto6gamma,4gto4gamma,2gto2gamma,7gammato8g,5gammato6g,3gammato4g,8gammato6gamma,6gammato4gamma,4gammato2gamma,7gammato5gamma,5gammato3gamma,7gammato6gamma,5gammato4gamma,3gammato2gamma},
              xticklabels={
              {$10_grightarrow8_g$},{$8_grightarrow6_g$},{$6_grightarrow4_g$},{$4_grightarrow2_g$},
              {$8_grightarrow8gamma$},{$6_grightarrow6gamma$},{$4_grightarrow4gamma$},{$2_grightarrow2gamma$},
              {$7_gammarightarrow8_g$},{$5_gammarightarrow6_g$},{$3_gammarightarrow4_g$},
              {$8_gammarightarrow6_gamma$},{$6_gammarightarrow4_gamma$},{$4_gammarightarrow2_gamma$},
              {$7_gammarightarrow5_gamma$},{$5_gammarightarrow3_gamma$},
              {$7_gammarightarrow6_gamma$},{$5_gammarightarrow4_gamma$},
              {$3_gammarightarrow2_gamma$}
              },
              nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
              nodes near coords align={vertical},
              nodes near coords style={rotate=90,anchor=west,font=small}
              ]


              addplot+[bar shift = -0.25cm]
              coordinates {(10gto8g,0)
              (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0)
              };
              %
              %
              addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };
              %
              % % Z5 coordinate was in twice
              addplot+[bar shift = 0.25cm] coordinates {(10gto8g,2.967)
              (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313)
              (3gammato2gamma,2.171)
              };

              end{axis}
              end{tikzpicture}
              end{document}


              enter image description here






              share|improve this answer


























              • Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

                – Hadi Sobhani
                Mar 4 at 6:01











              • @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

                – marmot
                Mar 4 at 6:06
















              2














              There were two issues:




              1. in the last plot you had coordinates twice.

              2. for some reason, pgfplots does not like a to. The deeper reason can be presumably found in pgfplots.code.tex, where to is used in many macros.


              I acknowledge that John Kormylo beat me by seconds (while I was typing the explanation).





              documentclass[tikz,border=3.15mm]{standalone}
              usepackage{pgfplots}
              pgfplotsset{compat=1.16,width=17.5cm}
              usepackage{comment}



              begin{document}
              begin{tikzpicture}
              begin{axis}[ybar,
              x tick label style={rotate=90},
              enlarge x limits=0.04,
              legend style={at={(0.85,1)},
              anchor=north,legend columns=-1},
              bar width=0.2cm,
              xtick=data,
              symbolic x coords={10gto8g,8gto6g,6gto4g,4gto2g,8gto8gamma,6gto6gamma,4gto4gamma,2gto2gamma,7gammato8g,5gammato6g,3gammato4g,8gammato6gamma,6gammato4gamma,4gammato2gamma,7gammato5gamma,5gammato3gamma,7gammato6gamma,5gammato4gamma,3gammato2gamma},
              xticklabels={
              {$10_grightarrow8_g$},{$8_grightarrow6_g$},{$6_grightarrow4_g$},{$4_grightarrow2_g$},
              {$8_grightarrow8gamma$},{$6_grightarrow6gamma$},{$4_grightarrow4gamma$},{$2_grightarrow2gamma$},
              {$7_gammarightarrow8_g$},{$5_gammarightarrow6_g$},{$3_gammarightarrow4_g$},
              {$8_gammarightarrow6_gamma$},{$6_gammarightarrow4_gamma$},{$4_gammarightarrow2_gamma$},
              {$7_gammarightarrow5_gamma$},{$5_gammarightarrow3_gamma$},
              {$7_gammarightarrow6_gamma$},{$5_gammarightarrow4_gamma$},
              {$3_gammarightarrow2_gamma$}
              },
              nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
              nodes near coords align={vertical},
              nodes near coords style={rotate=90,anchor=west,font=small}
              ]


              addplot+[bar shift = -0.25cm]
              coordinates {(10gto8g,0)
              (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0)
              };
              %
              %
              addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };
              %
              % % Z5 coordinate was in twice
              addplot+[bar shift = 0.25cm] coordinates {(10gto8g,2.967)
              (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313)
              (3gammato2gamma,2.171)
              };

              end{axis}
              end{tikzpicture}
              end{document}


              enter image description here






              share|improve this answer


























              • Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

                – Hadi Sobhani
                Mar 4 at 6:01











              • @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

                – marmot
                Mar 4 at 6:06














              2












              2








              2







              There were two issues:




              1. in the last plot you had coordinates twice.

              2. for some reason, pgfplots does not like a to. The deeper reason can be presumably found in pgfplots.code.tex, where to is used in many macros.


              I acknowledge that John Kormylo beat me by seconds (while I was typing the explanation).





              documentclass[tikz,border=3.15mm]{standalone}
              usepackage{pgfplots}
              pgfplotsset{compat=1.16,width=17.5cm}
              usepackage{comment}



              begin{document}
              begin{tikzpicture}
              begin{axis}[ybar,
              x tick label style={rotate=90},
              enlarge x limits=0.04,
              legend style={at={(0.85,1)},
              anchor=north,legend columns=-1},
              bar width=0.2cm,
              xtick=data,
              symbolic x coords={10gto8g,8gto6g,6gto4g,4gto2g,8gto8gamma,6gto6gamma,4gto4gamma,2gto2gamma,7gammato8g,5gammato6g,3gammato4g,8gammato6gamma,6gammato4gamma,4gammato2gamma,7gammato5gamma,5gammato3gamma,7gammato6gamma,5gammato4gamma,3gammato2gamma},
              xticklabels={
              {$10_grightarrow8_g$},{$8_grightarrow6_g$},{$6_grightarrow4_g$},{$4_grightarrow2_g$},
              {$8_grightarrow8gamma$},{$6_grightarrow6gamma$},{$4_grightarrow4gamma$},{$2_grightarrow2gamma$},
              {$7_gammarightarrow8_g$},{$5_gammarightarrow6_g$},{$3_gammarightarrow4_g$},
              {$8_gammarightarrow6_gamma$},{$6_gammarightarrow4_gamma$},{$4_gammarightarrow2_gamma$},
              {$7_gammarightarrow5_gamma$},{$5_gammarightarrow3_gamma$},
              {$7_gammarightarrow6_gamma$},{$5_gammarightarrow4_gamma$},
              {$3_gammarightarrow2_gamma$}
              },
              nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
              nodes near coords align={vertical},
              nodes near coords style={rotate=90,anchor=west,font=small}
              ]


              addplot+[bar shift = -0.25cm]
              coordinates {(10gto8g,0)
              (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0)
              };
              %
              %
              addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };
              %
              % % Z5 coordinate was in twice
              addplot+[bar shift = 0.25cm] coordinates {(10gto8g,2.967)
              (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313)
              (3gammato2gamma,2.171)
              };

              end{axis}
              end{tikzpicture}
              end{document}


              enter image description here






              share|improve this answer















              There were two issues:




              1. in the last plot you had coordinates twice.

              2. for some reason, pgfplots does not like a to. The deeper reason can be presumably found in pgfplots.code.tex, where to is used in many macros.


              I acknowledge that John Kormylo beat me by seconds (while I was typing the explanation).





              documentclass[tikz,border=3.15mm]{standalone}
              usepackage{pgfplots}
              pgfplotsset{compat=1.16,width=17.5cm}
              usepackage{comment}



              begin{document}
              begin{tikzpicture}
              begin{axis}[ybar,
              x tick label style={rotate=90},
              enlarge x limits=0.04,
              legend style={at={(0.85,1)},
              anchor=north,legend columns=-1},
              bar width=0.2cm,
              xtick=data,
              symbolic x coords={10gto8g,8gto6g,6gto4g,4gto2g,8gto8gamma,6gto6gamma,4gto4gamma,2gto2gamma,7gammato8g,5gammato6g,3gammato4g,8gammato6gamma,6gammato4gamma,4gammato2gamma,7gammato5gamma,5gammato3gamma,7gammato6gamma,5gammato4gamma,3gammato2gamma},
              xticklabels={
              {$10_grightarrow8_g$},{$8_grightarrow6_g$},{$6_grightarrow4_g$},{$4_grightarrow2_g$},
              {$8_grightarrow8gamma$},{$6_grightarrow6gamma$},{$4_grightarrow4gamma$},{$2_grightarrow2gamma$},
              {$7_gammarightarrow8_g$},{$5_gammarightarrow6_g$},{$3_gammarightarrow4_g$},
              {$8_gammarightarrow6_gamma$},{$6_gammarightarrow4_gamma$},{$4_gammarightarrow2_gamma$},
              {$7_gammarightarrow5_gamma$},{$5_gammarightarrow3_gamma$},
              {$7_gammarightarrow6_gamma$},{$5_gammarightarrow4_gamma$},
              {$3_gammarightarrow2_gamma$}
              },
              nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
              nodes near coords align={vertical},
              nodes near coords style={rotate=90,anchor=west,font=small}
              ]


              addplot+[bar shift = -0.25cm]
              coordinates {(10gto8g,0)
              (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0)
              };
              %
              %
              addplot+[bar shift = 0cm] coordinates {(10gto8g,0) (8gto6g,0) (6gto4g,0) (4gto2g,0) (8gto8gamma,0) (6gto6gamma,0) (4gto4gamma,0) (2gto2gamma,0) (7gammato8g,0) (5gammato6g,0) (3gammato4g,0) (8gammato6gamma,0) (6gammato4gamma,0) (4gammato2gamma,0) (7gammato5gamma,0) (5gammato3gamma,0) (7gammato6gamma,0) (5gammato4gamma,0) (3gammato2gamma,0) };
              %
              % % Z5 coordinate was in twice
              addplot+[bar shift = 0.25cm] coordinates {(10gto8g,2.967)
              (8gto6g,2.635) (6gto4g,2.203) (4gto2g,1.590) (8gto8gamma,0.1290) (6gto6gamma,0.1976) (4gto4gamma,0.3481) (2gto2gamma,1.620) (7gammato8g,0.808) (5gammato6g,0.972) (3gammato4g,1.243) (8gammato6gamma,1.590) (6gammato4gamma,1.031) (4gammato2gamma,0.736) (7gammato5gamma,1.851) (5gammato3gamma,1.235) (7gammato6gamma,1.260) (5gammato4gamma,1.313)
              (3gammato2gamma,2.171)
              };

              end{axis}
              end{tikzpicture}
              end{document}


              enter image description here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 4 at 6:11

























              answered Mar 4 at 5:56









              marmotmarmot

              107k5130244




              107k5130244













              • Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

                – Hadi Sobhani
                Mar 4 at 6:01











              • @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

                – marmot
                Mar 4 at 6:06



















              • Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

                – Hadi Sobhani
                Mar 4 at 6:01











              • @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

                – marmot
                Mar 4 at 6:06

















              Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

              – Hadi Sobhani
              Mar 4 at 6:01





              Dear @marmot, as it can be seen, for each xtick there are three bars, but all of them are next to each other. How can I make a space between each xtick?

              – Hadi Sobhani
              Mar 4 at 6:01













              @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

              – marmot
              Mar 4 at 6:06





              @HadiSobhani You might want to increase the width of the plot, e.g. pgfplotsset{compat=1.16,width=17.5cm} and decrease the padding, e.g. enlarge x limits=0.04, instead of 0.1.

              – marmot
              Mar 4 at 6:06











              4














              Tikz redefines to. Use rightarrow instead. Also, it seems that symbolic x coordinates and xticklables are incompatible.



              documentclass[tikz,border=3.15mm]{standalone}
              usepackage{pgfplots}
              pgfplotsset{compat=1.16,width=15.5cm}
              usepackage{comment}

              begin{document}
              begin{tikzpicture}
              begin{axis}[
              ybar,
              xtick=data,
              x tick label style={rotate=90},
              enlarge x limits=0.1,
              legend style={at={(0.85,1)},
              anchor=north,legend columns=-1},
              bar width = 0.2 cm,
              nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
              nodes near coords align={vertical},
              nodes near coords style={rotate=90,anchor=west,font=small},
              xticklabels={
              {$ 10_g rightarrow 8_g $}, {$ 8_g rightarrow 6_g $}, {$ 6_g rightarrow 4_g $}, {$ 4_g rightarrow 2_g $},
              {$ 8_g rightarrow 8gamma $}, {$ 6_g rightarrow 6gamma $}, {$ 4_g rightarrow 4gamma $}, {$ 2_g rightarrow 2gamma $},
              {$ 7_gamma rightarrow 8_g $}, {$ 5_gamma rightarrow 6_g $}, {$ 3_gamma rightarrow 4_g $},
              {$ 8_gamma rightarrow 6_gamma $}, {$ 6_gamma rightarrow 4_gamma $}, {$ 4_gamma rightarrow 2_gamma $},
              {$ 7_gamma rightarrow 5_gamma $}, {$ 5_gamma rightarrow 3_gamma $},
              {$ 7_gamma rightarrow 6_gamma $}, {$ 5_gamma rightarrow 4_gamma $}, {$ 3_gamma rightarrow 2_gamma $}
              },
              ]

              addplot+[bar shift = -0.25cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

              addplot+[bar shift = 0cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

              % Z5
              addplot+[bar shift = 0.25cm] coordinates {(1,2.967) (2,2.635) (3,2.203) (4,1.590) (5,0.1290) (6,0.1976) (7,0.3481) (8,1.620) (9,0.808) (10,0.972) (11,1.243) (12,1.590) (13,1.031) (14,0.736) (15,1.851) (16,1.235) (17,1.260) (18,1.313) (19,2.171) };

              end{axis}
              end{tikzpicture}

              end{document}


              demo





              It occurred to me that it might be better to record the data in table format.



              documentclass[tikz,border=3.15mm]{standalone}
              usepackage{pgfplots}
              pgfplotsset{compat=1.16,width=15.5cm}
              usepackage{pgfplotstable}

              newcommand{mylabels}{}% reserve global name

              begin{document}
              pgfplotstableread[col sep=comma, string type]{
              x, name, label, y1, y2, y3
              1, 10gto8g, $10_g rightarrow 8_g$, 0,0,2.967
              2, 8gto6g, $8_g rightarrow 6_g$, 0,0,2.635
              3, 6gto4g, $6_g rightarrow 4_g$, 0,0,2.203
              4, 4gto2g, $4_g rightarrow 2_g$, 0,0,1.590
              5, 8gto8gamma, $8_g rightarrow 8gamma$, 0,0,0.1290
              6, 6gto6gamma, $6_g rightarrow 6gamma$, 0,0,0.1976
              7, 4gto4gamma, $4_g rightarrow 4gamma$, 0,0,0.3481
              8, 2gto2gamma, $2_g rightarrow 2gamma$, 0,0,1.620
              9, 7gammato8g, $7_gamma rightarrow 8_g$, 0,0,0.808
              10, 5gammato6g, $5_gamma rightarrow 6_g$, 0,0,0.972
              11, 3gammato4g, $3_gamma rightarrow 4_g$, 0,0,1.243
              12, 8gammato6gamma, $8_gamma rightarrow 6_gamma$, 0,0,1.590
              13, 6gammato4gamma, $6_gamma rightarrow 4_gamma$, 0,0,1.031
              14, 4gammato2gamma, $4_gamma rightarrow 2_gamma$, 0,0,0.736
              15, 7gammato5gamma, $7_gamma rightarrow 5_gamma$, 0,0,1.851
              16, 5gammato3gamma, $5_gamma rightarrow 3_gamma$, 0,0,1.235
              17, 7gammato6gamma, $7_gamma rightarrow 6_gamma$, 0,0,1.260
              18, 5gammato4gamma, $5_gamma rightarrow 4_gamma$, 0,0,1.313
              19, 3gammato2gamma, $3_gamma rightarrow 2_gamma$, 0,0,2.171
              }mytable

              %pgfplotstabletypeset[string type]mytable% error check
              pgfplotstablegetelem{0}{label}ofmytable% put labels into macro mylabels
              xdefmylabels{pgfplotsretval}%
              foreach i in {1,2,...,18}{pgfplotstablegetelem{i}{label}ofmytable
              xdefmylabels{mylabels,pgfplotsretval}}%

              begin{tikzpicture}
              begin{axis}[
              ybar,
              xtick=data,
              x tick label style={rotate=90},
              enlarge x limits=0.1,
              legend style={at={(0.85,1)},
              anchor=north,legend columns=-1},
              bar width = 0.2 cm,
              nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
              nodes near coords align={vertical},
              nodes near coords style={rotate=90,anchor=west,font=small},
              xticklabels/.expand once=mylabels
              ]

              addplot+[bar shift = -0.25cm] table[x=x, y=y1] mytable;
              addplot+[bar shift = 0cm] table[x=x, y=y2] mytable;
              addplot+[bar shift = 0.25cm] table[x=x, y=y3] mytable;
              end{axis}
              end{tikzpicture}

              end{document}





              share|improve this answer






























                4














                Tikz redefines to. Use rightarrow instead. Also, it seems that symbolic x coordinates and xticklables are incompatible.



                documentclass[tikz,border=3.15mm]{standalone}
                usepackage{pgfplots}
                pgfplotsset{compat=1.16,width=15.5cm}
                usepackage{comment}

                begin{document}
                begin{tikzpicture}
                begin{axis}[
                ybar,
                xtick=data,
                x tick label style={rotate=90},
                enlarge x limits=0.1,
                legend style={at={(0.85,1)},
                anchor=north,legend columns=-1},
                bar width = 0.2 cm,
                nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                nodes near coords align={vertical},
                nodes near coords style={rotate=90,anchor=west,font=small},
                xticklabels={
                {$ 10_g rightarrow 8_g $}, {$ 8_g rightarrow 6_g $}, {$ 6_g rightarrow 4_g $}, {$ 4_g rightarrow 2_g $},
                {$ 8_g rightarrow 8gamma $}, {$ 6_g rightarrow 6gamma $}, {$ 4_g rightarrow 4gamma $}, {$ 2_g rightarrow 2gamma $},
                {$ 7_gamma rightarrow 8_g $}, {$ 5_gamma rightarrow 6_g $}, {$ 3_gamma rightarrow 4_g $},
                {$ 8_gamma rightarrow 6_gamma $}, {$ 6_gamma rightarrow 4_gamma $}, {$ 4_gamma rightarrow 2_gamma $},
                {$ 7_gamma rightarrow 5_gamma $}, {$ 5_gamma rightarrow 3_gamma $},
                {$ 7_gamma rightarrow 6_gamma $}, {$ 5_gamma rightarrow 4_gamma $}, {$ 3_gamma rightarrow 2_gamma $}
                },
                ]

                addplot+[bar shift = -0.25cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

                addplot+[bar shift = 0cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

                % Z5
                addplot+[bar shift = 0.25cm] coordinates {(1,2.967) (2,2.635) (3,2.203) (4,1.590) (5,0.1290) (6,0.1976) (7,0.3481) (8,1.620) (9,0.808) (10,0.972) (11,1.243) (12,1.590) (13,1.031) (14,0.736) (15,1.851) (16,1.235) (17,1.260) (18,1.313) (19,2.171) };

                end{axis}
                end{tikzpicture}

                end{document}


                demo





                It occurred to me that it might be better to record the data in table format.



                documentclass[tikz,border=3.15mm]{standalone}
                usepackage{pgfplots}
                pgfplotsset{compat=1.16,width=15.5cm}
                usepackage{pgfplotstable}

                newcommand{mylabels}{}% reserve global name

                begin{document}
                pgfplotstableread[col sep=comma, string type]{
                x, name, label, y1, y2, y3
                1, 10gto8g, $10_g rightarrow 8_g$, 0,0,2.967
                2, 8gto6g, $8_g rightarrow 6_g$, 0,0,2.635
                3, 6gto4g, $6_g rightarrow 4_g$, 0,0,2.203
                4, 4gto2g, $4_g rightarrow 2_g$, 0,0,1.590
                5, 8gto8gamma, $8_g rightarrow 8gamma$, 0,0,0.1290
                6, 6gto6gamma, $6_g rightarrow 6gamma$, 0,0,0.1976
                7, 4gto4gamma, $4_g rightarrow 4gamma$, 0,0,0.3481
                8, 2gto2gamma, $2_g rightarrow 2gamma$, 0,0,1.620
                9, 7gammato8g, $7_gamma rightarrow 8_g$, 0,0,0.808
                10, 5gammato6g, $5_gamma rightarrow 6_g$, 0,0,0.972
                11, 3gammato4g, $3_gamma rightarrow 4_g$, 0,0,1.243
                12, 8gammato6gamma, $8_gamma rightarrow 6_gamma$, 0,0,1.590
                13, 6gammato4gamma, $6_gamma rightarrow 4_gamma$, 0,0,1.031
                14, 4gammato2gamma, $4_gamma rightarrow 2_gamma$, 0,0,0.736
                15, 7gammato5gamma, $7_gamma rightarrow 5_gamma$, 0,0,1.851
                16, 5gammato3gamma, $5_gamma rightarrow 3_gamma$, 0,0,1.235
                17, 7gammato6gamma, $7_gamma rightarrow 6_gamma$, 0,0,1.260
                18, 5gammato4gamma, $5_gamma rightarrow 4_gamma$, 0,0,1.313
                19, 3gammato2gamma, $3_gamma rightarrow 2_gamma$, 0,0,2.171
                }mytable

                %pgfplotstabletypeset[string type]mytable% error check
                pgfplotstablegetelem{0}{label}ofmytable% put labels into macro mylabels
                xdefmylabels{pgfplotsretval}%
                foreach i in {1,2,...,18}{pgfplotstablegetelem{i}{label}ofmytable
                xdefmylabels{mylabels,pgfplotsretval}}%

                begin{tikzpicture}
                begin{axis}[
                ybar,
                xtick=data,
                x tick label style={rotate=90},
                enlarge x limits=0.1,
                legend style={at={(0.85,1)},
                anchor=north,legend columns=-1},
                bar width = 0.2 cm,
                nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                nodes near coords align={vertical},
                nodes near coords style={rotate=90,anchor=west,font=small},
                xticklabels/.expand once=mylabels
                ]

                addplot+[bar shift = -0.25cm] table[x=x, y=y1] mytable;
                addplot+[bar shift = 0cm] table[x=x, y=y2] mytable;
                addplot+[bar shift = 0.25cm] table[x=x, y=y3] mytable;
                end{axis}
                end{tikzpicture}

                end{document}





                share|improve this answer




























                  4












                  4








                  4







                  Tikz redefines to. Use rightarrow instead. Also, it seems that symbolic x coordinates and xticklables are incompatible.



                  documentclass[tikz,border=3.15mm]{standalone}
                  usepackage{pgfplots}
                  pgfplotsset{compat=1.16,width=15.5cm}
                  usepackage{comment}

                  begin{document}
                  begin{tikzpicture}
                  begin{axis}[
                  ybar,
                  xtick=data,
                  x tick label style={rotate=90},
                  enlarge x limits=0.1,
                  legend style={at={(0.85,1)},
                  anchor=north,legend columns=-1},
                  bar width = 0.2 cm,
                  nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                  nodes near coords align={vertical},
                  nodes near coords style={rotate=90,anchor=west,font=small},
                  xticklabels={
                  {$ 10_g rightarrow 8_g $}, {$ 8_g rightarrow 6_g $}, {$ 6_g rightarrow 4_g $}, {$ 4_g rightarrow 2_g $},
                  {$ 8_g rightarrow 8gamma $}, {$ 6_g rightarrow 6gamma $}, {$ 4_g rightarrow 4gamma $}, {$ 2_g rightarrow 2gamma $},
                  {$ 7_gamma rightarrow 8_g $}, {$ 5_gamma rightarrow 6_g $}, {$ 3_gamma rightarrow 4_g $},
                  {$ 8_gamma rightarrow 6_gamma $}, {$ 6_gamma rightarrow 4_gamma $}, {$ 4_gamma rightarrow 2_gamma $},
                  {$ 7_gamma rightarrow 5_gamma $}, {$ 5_gamma rightarrow 3_gamma $},
                  {$ 7_gamma rightarrow 6_gamma $}, {$ 5_gamma rightarrow 4_gamma $}, {$ 3_gamma rightarrow 2_gamma $}
                  },
                  ]

                  addplot+[bar shift = -0.25cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

                  addplot+[bar shift = 0cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

                  % Z5
                  addplot+[bar shift = 0.25cm] coordinates {(1,2.967) (2,2.635) (3,2.203) (4,1.590) (5,0.1290) (6,0.1976) (7,0.3481) (8,1.620) (9,0.808) (10,0.972) (11,1.243) (12,1.590) (13,1.031) (14,0.736) (15,1.851) (16,1.235) (17,1.260) (18,1.313) (19,2.171) };

                  end{axis}
                  end{tikzpicture}

                  end{document}


                  demo





                  It occurred to me that it might be better to record the data in table format.



                  documentclass[tikz,border=3.15mm]{standalone}
                  usepackage{pgfplots}
                  pgfplotsset{compat=1.16,width=15.5cm}
                  usepackage{pgfplotstable}

                  newcommand{mylabels}{}% reserve global name

                  begin{document}
                  pgfplotstableread[col sep=comma, string type]{
                  x, name, label, y1, y2, y3
                  1, 10gto8g, $10_g rightarrow 8_g$, 0,0,2.967
                  2, 8gto6g, $8_g rightarrow 6_g$, 0,0,2.635
                  3, 6gto4g, $6_g rightarrow 4_g$, 0,0,2.203
                  4, 4gto2g, $4_g rightarrow 2_g$, 0,0,1.590
                  5, 8gto8gamma, $8_g rightarrow 8gamma$, 0,0,0.1290
                  6, 6gto6gamma, $6_g rightarrow 6gamma$, 0,0,0.1976
                  7, 4gto4gamma, $4_g rightarrow 4gamma$, 0,0,0.3481
                  8, 2gto2gamma, $2_g rightarrow 2gamma$, 0,0,1.620
                  9, 7gammato8g, $7_gamma rightarrow 8_g$, 0,0,0.808
                  10, 5gammato6g, $5_gamma rightarrow 6_g$, 0,0,0.972
                  11, 3gammato4g, $3_gamma rightarrow 4_g$, 0,0,1.243
                  12, 8gammato6gamma, $8_gamma rightarrow 6_gamma$, 0,0,1.590
                  13, 6gammato4gamma, $6_gamma rightarrow 4_gamma$, 0,0,1.031
                  14, 4gammato2gamma, $4_gamma rightarrow 2_gamma$, 0,0,0.736
                  15, 7gammato5gamma, $7_gamma rightarrow 5_gamma$, 0,0,1.851
                  16, 5gammato3gamma, $5_gamma rightarrow 3_gamma$, 0,0,1.235
                  17, 7gammato6gamma, $7_gamma rightarrow 6_gamma$, 0,0,1.260
                  18, 5gammato4gamma, $5_gamma rightarrow 4_gamma$, 0,0,1.313
                  19, 3gammato2gamma, $3_gamma rightarrow 2_gamma$, 0,0,2.171
                  }mytable

                  %pgfplotstabletypeset[string type]mytable% error check
                  pgfplotstablegetelem{0}{label}ofmytable% put labels into macro mylabels
                  xdefmylabels{pgfplotsretval}%
                  foreach i in {1,2,...,18}{pgfplotstablegetelem{i}{label}ofmytable
                  xdefmylabels{mylabels,pgfplotsretval}}%

                  begin{tikzpicture}
                  begin{axis}[
                  ybar,
                  xtick=data,
                  x tick label style={rotate=90},
                  enlarge x limits=0.1,
                  legend style={at={(0.85,1)},
                  anchor=north,legend columns=-1},
                  bar width = 0.2 cm,
                  nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                  nodes near coords align={vertical},
                  nodes near coords style={rotate=90,anchor=west,font=small},
                  xticklabels/.expand once=mylabels
                  ]

                  addplot+[bar shift = -0.25cm] table[x=x, y=y1] mytable;
                  addplot+[bar shift = 0cm] table[x=x, y=y2] mytable;
                  addplot+[bar shift = 0.25cm] table[x=x, y=y3] mytable;
                  end{axis}
                  end{tikzpicture}

                  end{document}





                  share|improve this answer















                  Tikz redefines to. Use rightarrow instead. Also, it seems that symbolic x coordinates and xticklables are incompatible.



                  documentclass[tikz,border=3.15mm]{standalone}
                  usepackage{pgfplots}
                  pgfplotsset{compat=1.16,width=15.5cm}
                  usepackage{comment}

                  begin{document}
                  begin{tikzpicture}
                  begin{axis}[
                  ybar,
                  xtick=data,
                  x tick label style={rotate=90},
                  enlarge x limits=0.1,
                  legend style={at={(0.85,1)},
                  anchor=north,legend columns=-1},
                  bar width = 0.2 cm,
                  nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                  nodes near coords align={vertical},
                  nodes near coords style={rotate=90,anchor=west,font=small},
                  xticklabels={
                  {$ 10_g rightarrow 8_g $}, {$ 8_g rightarrow 6_g $}, {$ 6_g rightarrow 4_g $}, {$ 4_g rightarrow 2_g $},
                  {$ 8_g rightarrow 8gamma $}, {$ 6_g rightarrow 6gamma $}, {$ 4_g rightarrow 4gamma $}, {$ 2_g rightarrow 2gamma $},
                  {$ 7_gamma rightarrow 8_g $}, {$ 5_gamma rightarrow 6_g $}, {$ 3_gamma rightarrow 4_g $},
                  {$ 8_gamma rightarrow 6_gamma $}, {$ 6_gamma rightarrow 4_gamma $}, {$ 4_gamma rightarrow 2_gamma $},
                  {$ 7_gamma rightarrow 5_gamma $}, {$ 5_gamma rightarrow 3_gamma $},
                  {$ 7_gamma rightarrow 6_gamma $}, {$ 5_gamma rightarrow 4_gamma $}, {$ 3_gamma rightarrow 2_gamma $}
                  },
                  ]

                  addplot+[bar shift = -0.25cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

                  addplot+[bar shift = 0cm] coordinates {(1,0) (2,0) (3,0) (4,0) (5,0) (6,0) (7,0) (8,0) (9,0) (10,0) (11,0) (12,0) (13,0) (14,0) (15,0) (16,0) (17,0) (18,0) (19,0) };

                  % Z5
                  addplot+[bar shift = 0.25cm] coordinates {(1,2.967) (2,2.635) (3,2.203) (4,1.590) (5,0.1290) (6,0.1976) (7,0.3481) (8,1.620) (9,0.808) (10,0.972) (11,1.243) (12,1.590) (13,1.031) (14,0.736) (15,1.851) (16,1.235) (17,1.260) (18,1.313) (19,2.171) };

                  end{axis}
                  end{tikzpicture}

                  end{document}


                  demo





                  It occurred to me that it might be better to record the data in table format.



                  documentclass[tikz,border=3.15mm]{standalone}
                  usepackage{pgfplots}
                  pgfplotsset{compat=1.16,width=15.5cm}
                  usepackage{pgfplotstable}

                  newcommand{mylabels}{}% reserve global name

                  begin{document}
                  pgfplotstableread[col sep=comma, string type]{
                  x, name, label, y1, y2, y3
                  1, 10gto8g, $10_g rightarrow 8_g$, 0,0,2.967
                  2, 8gto6g, $8_g rightarrow 6_g$, 0,0,2.635
                  3, 6gto4g, $6_g rightarrow 4_g$, 0,0,2.203
                  4, 4gto2g, $4_g rightarrow 2_g$, 0,0,1.590
                  5, 8gto8gamma, $8_g rightarrow 8gamma$, 0,0,0.1290
                  6, 6gto6gamma, $6_g rightarrow 6gamma$, 0,0,0.1976
                  7, 4gto4gamma, $4_g rightarrow 4gamma$, 0,0,0.3481
                  8, 2gto2gamma, $2_g rightarrow 2gamma$, 0,0,1.620
                  9, 7gammato8g, $7_gamma rightarrow 8_g$, 0,0,0.808
                  10, 5gammato6g, $5_gamma rightarrow 6_g$, 0,0,0.972
                  11, 3gammato4g, $3_gamma rightarrow 4_g$, 0,0,1.243
                  12, 8gammato6gamma, $8_gamma rightarrow 6_gamma$, 0,0,1.590
                  13, 6gammato4gamma, $6_gamma rightarrow 4_gamma$, 0,0,1.031
                  14, 4gammato2gamma, $4_gamma rightarrow 2_gamma$, 0,0,0.736
                  15, 7gammato5gamma, $7_gamma rightarrow 5_gamma$, 0,0,1.851
                  16, 5gammato3gamma, $5_gamma rightarrow 3_gamma$, 0,0,1.235
                  17, 7gammato6gamma, $7_gamma rightarrow 6_gamma$, 0,0,1.260
                  18, 5gammato4gamma, $5_gamma rightarrow 4_gamma$, 0,0,1.313
                  19, 3gammato2gamma, $3_gamma rightarrow 2_gamma$, 0,0,2.171
                  }mytable

                  %pgfplotstabletypeset[string type]mytable% error check
                  pgfplotstablegetelem{0}{label}ofmytable% put labels into macro mylabels
                  xdefmylabels{pgfplotsretval}%
                  foreach i in {1,2,...,18}{pgfplotstablegetelem{i}{label}ofmytable
                  xdefmylabels{mylabels,pgfplotsretval}}%

                  begin{tikzpicture}
                  begin{axis}[
                  ybar,
                  xtick=data,
                  x tick label style={rotate=90},
                  enlarge x limits=0.1,
                  legend style={at={(0.85,1)},
                  anchor=north,legend columns=-1},
                  bar width = 0.2 cm,
                  nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                  nodes near coords align={vertical},
                  nodes near coords style={rotate=90,anchor=west,font=small},
                  xticklabels/.expand once=mylabels
                  ]

                  addplot+[bar shift = -0.25cm] table[x=x, y=y1] mytable;
                  addplot+[bar shift = 0cm] table[x=x, y=y2] mytable;
                  addplot+[bar shift = 0.25cm] table[x=x, y=y3] mytable;
                  end{axis}
                  end{tikzpicture}

                  end{document}






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 4 at 16:57

























                  answered Mar 4 at 5:54









                  John KormyloJohn Kormylo

                  45.1k12570




                  45.1k12570























                      1














                      with use of pgfplotstable you will not have problem with use of to math symbol. beside this code is simpler, a bit shorter and to my opinion more clear. based on my answer on your previous question, i rewrite your mwe to:



                      documentclass[margin=3mm]{standalone}
                      usepackage{pgfplotstable}
                      pgfplotsset{compat=1.16}

                      begin{document}
                      begin{tikzpicture}
                      pgfplotstableread{
                      X Y1 Y2 Y3
                      $10_gto 8_g$ 0 0 2.967
                      $8_gto 6_g$ 0 0 2.635
                      $6_gto 4_g$ 0 0 2.203
                      $4_gto 2_g$ 0 0 1.590
                      $8_gto 8gamma$ 0 0 0.1290
                      $6_gto 6gamma$ 0 0 0.1976
                      $4_gto 4gamma$ 0 0 0.3481
                      $2_gto 2gamma$ 0 0 1.6204
                      $8_gammato 6_gamma$ 0 0 1.590
                      $6_gammato 4_gamma$ 0 0 1.031
                      $4_gammato 2_gamma$ 0 0 0.736
                      $8_gammato 6_gamma$ 0 0 1.590
                      $6_gammato 4_gamma$ 0 0 1.031
                      $4_gammato 2_gamma$ 0 0 0.736
                      $7_gammato 5_gamma$ 0 0 1.851
                      $5_gammato 3_gamma$ 0 0 1.235
                      $7_gammato 6_gamma$ 0 0 1.260
                      $5_gammato 4_gamma$ 0 0 1.313
                      $3_gammato 2_gamma$ 0 0 2.171
                      }mydata

                      begin{axis}[width=160mm,
                      enlarge x limits=0.04,
                      enlarge y limits=0.01,
                      legend style={legend columns=-1,
                      % legend pos=north east,
                      font=footnotesize,
                      /tikz/every even column/.append style={column sep=2mm},
                      anchor=north,
                      at={(0.5,-0.12)},
                      },
                      ybar=0.4mm, % distance between bars (shift bar)
                      bar width=1.8mm, % width of bars
                      nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                      nodes near coords style={font=scriptsize, inner sep=2pt, rotate=90, anchor=west},
                      nodes near coords align={vertical},
                      ymin=0, ymax=3.5,
                      ytick={0,0.5,...,3.5},
                      %
                      xtick=data,
                      xticklabels from table = {mydata}{X},
                      x tick label style={rotate=90, anchor=east},
                      scale only axis,
                      ]
                      addplot table[x expr=coordindex,y index=1] {mydata};
                      addplot table[x expr=coordindex,y index=2] {mydata};
                      addplot table[x expr=coordindex,y index=3] {mydata};

                      legend{used,understood,not understood}
                      end{axis}
                      end{tikzpicture}
                      end{document}


                      gives:



                      enter image description here






                      share|improve this answer






























                        1














                        with use of pgfplotstable you will not have problem with use of to math symbol. beside this code is simpler, a bit shorter and to my opinion more clear. based on my answer on your previous question, i rewrite your mwe to:



                        documentclass[margin=3mm]{standalone}
                        usepackage{pgfplotstable}
                        pgfplotsset{compat=1.16}

                        begin{document}
                        begin{tikzpicture}
                        pgfplotstableread{
                        X Y1 Y2 Y3
                        $10_gto 8_g$ 0 0 2.967
                        $8_gto 6_g$ 0 0 2.635
                        $6_gto 4_g$ 0 0 2.203
                        $4_gto 2_g$ 0 0 1.590
                        $8_gto 8gamma$ 0 0 0.1290
                        $6_gto 6gamma$ 0 0 0.1976
                        $4_gto 4gamma$ 0 0 0.3481
                        $2_gto 2gamma$ 0 0 1.6204
                        $8_gammato 6_gamma$ 0 0 1.590
                        $6_gammato 4_gamma$ 0 0 1.031
                        $4_gammato 2_gamma$ 0 0 0.736
                        $8_gammato 6_gamma$ 0 0 1.590
                        $6_gammato 4_gamma$ 0 0 1.031
                        $4_gammato 2_gamma$ 0 0 0.736
                        $7_gammato 5_gamma$ 0 0 1.851
                        $5_gammato 3_gamma$ 0 0 1.235
                        $7_gammato 6_gamma$ 0 0 1.260
                        $5_gammato 4_gamma$ 0 0 1.313
                        $3_gammato 2_gamma$ 0 0 2.171
                        }mydata

                        begin{axis}[width=160mm,
                        enlarge x limits=0.04,
                        enlarge y limits=0.01,
                        legend style={legend columns=-1,
                        % legend pos=north east,
                        font=footnotesize,
                        /tikz/every even column/.append style={column sep=2mm},
                        anchor=north,
                        at={(0.5,-0.12)},
                        },
                        ybar=0.4mm, % distance between bars (shift bar)
                        bar width=1.8mm, % width of bars
                        nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                        nodes near coords style={font=scriptsize, inner sep=2pt, rotate=90, anchor=west},
                        nodes near coords align={vertical},
                        ymin=0, ymax=3.5,
                        ytick={0,0.5,...,3.5},
                        %
                        xtick=data,
                        xticklabels from table = {mydata}{X},
                        x tick label style={rotate=90, anchor=east},
                        scale only axis,
                        ]
                        addplot table[x expr=coordindex,y index=1] {mydata};
                        addplot table[x expr=coordindex,y index=2] {mydata};
                        addplot table[x expr=coordindex,y index=3] {mydata};

                        legend{used,understood,not understood}
                        end{axis}
                        end{tikzpicture}
                        end{document}


                        gives:



                        enter image description here






                        share|improve this answer




























                          1












                          1








                          1







                          with use of pgfplotstable you will not have problem with use of to math symbol. beside this code is simpler, a bit shorter and to my opinion more clear. based on my answer on your previous question, i rewrite your mwe to:



                          documentclass[margin=3mm]{standalone}
                          usepackage{pgfplotstable}
                          pgfplotsset{compat=1.16}

                          begin{document}
                          begin{tikzpicture}
                          pgfplotstableread{
                          X Y1 Y2 Y3
                          $10_gto 8_g$ 0 0 2.967
                          $8_gto 6_g$ 0 0 2.635
                          $6_gto 4_g$ 0 0 2.203
                          $4_gto 2_g$ 0 0 1.590
                          $8_gto 8gamma$ 0 0 0.1290
                          $6_gto 6gamma$ 0 0 0.1976
                          $4_gto 4gamma$ 0 0 0.3481
                          $2_gto 2gamma$ 0 0 1.6204
                          $8_gammato 6_gamma$ 0 0 1.590
                          $6_gammato 4_gamma$ 0 0 1.031
                          $4_gammato 2_gamma$ 0 0 0.736
                          $8_gammato 6_gamma$ 0 0 1.590
                          $6_gammato 4_gamma$ 0 0 1.031
                          $4_gammato 2_gamma$ 0 0 0.736
                          $7_gammato 5_gamma$ 0 0 1.851
                          $5_gammato 3_gamma$ 0 0 1.235
                          $7_gammato 6_gamma$ 0 0 1.260
                          $5_gammato 4_gamma$ 0 0 1.313
                          $3_gammato 2_gamma$ 0 0 2.171
                          }mydata

                          begin{axis}[width=160mm,
                          enlarge x limits=0.04,
                          enlarge y limits=0.01,
                          legend style={legend columns=-1,
                          % legend pos=north east,
                          font=footnotesize,
                          /tikz/every even column/.append style={column sep=2mm},
                          anchor=north,
                          at={(0.5,-0.12)},
                          },
                          ybar=0.4mm, % distance between bars (shift bar)
                          bar width=1.8mm, % width of bars
                          nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                          nodes near coords style={font=scriptsize, inner sep=2pt, rotate=90, anchor=west},
                          nodes near coords align={vertical},
                          ymin=0, ymax=3.5,
                          ytick={0,0.5,...,3.5},
                          %
                          xtick=data,
                          xticklabels from table = {mydata}{X},
                          x tick label style={rotate=90, anchor=east},
                          scale only axis,
                          ]
                          addplot table[x expr=coordindex,y index=1] {mydata};
                          addplot table[x expr=coordindex,y index=2] {mydata};
                          addplot table[x expr=coordindex,y index=3] {mydata};

                          legend{used,understood,not understood}
                          end{axis}
                          end{tikzpicture}
                          end{document}


                          gives:



                          enter image description here






                          share|improve this answer















                          with use of pgfplotstable you will not have problem with use of to math symbol. beside this code is simpler, a bit shorter and to my opinion more clear. based on my answer on your previous question, i rewrite your mwe to:



                          documentclass[margin=3mm]{standalone}
                          usepackage{pgfplotstable}
                          pgfplotsset{compat=1.16}

                          begin{document}
                          begin{tikzpicture}
                          pgfplotstableread{
                          X Y1 Y2 Y3
                          $10_gto 8_g$ 0 0 2.967
                          $8_gto 6_g$ 0 0 2.635
                          $6_gto 4_g$ 0 0 2.203
                          $4_gto 2_g$ 0 0 1.590
                          $8_gto 8gamma$ 0 0 0.1290
                          $6_gto 6gamma$ 0 0 0.1976
                          $4_gto 4gamma$ 0 0 0.3481
                          $2_gto 2gamma$ 0 0 1.6204
                          $8_gammato 6_gamma$ 0 0 1.590
                          $6_gammato 4_gamma$ 0 0 1.031
                          $4_gammato 2_gamma$ 0 0 0.736
                          $8_gammato 6_gamma$ 0 0 1.590
                          $6_gammato 4_gamma$ 0 0 1.031
                          $4_gammato 2_gamma$ 0 0 0.736
                          $7_gammato 5_gamma$ 0 0 1.851
                          $5_gammato 3_gamma$ 0 0 1.235
                          $7_gammato 6_gamma$ 0 0 1.260
                          $5_gammato 4_gamma$ 0 0 1.313
                          $3_gammato 2_gamma$ 0 0 2.171
                          }mydata

                          begin{axis}[width=160mm,
                          enlarge x limits=0.04,
                          enlarge y limits=0.01,
                          legend style={legend columns=-1,
                          % legend pos=north east,
                          font=footnotesize,
                          /tikz/every even column/.append style={column sep=2mm},
                          anchor=north,
                          at={(0.5,-0.12)},
                          },
                          ybar=0.4mm, % distance between bars (shift bar)
                          bar width=1.8mm, % width of bars
                          nodes near coords={pgfmathprintnumber[precision=3]{pgfplotspointmeta}},
                          nodes near coords style={font=scriptsize, inner sep=2pt, rotate=90, anchor=west},
                          nodes near coords align={vertical},
                          ymin=0, ymax=3.5,
                          ytick={0,0.5,...,3.5},
                          %
                          xtick=data,
                          xticklabels from table = {mydata}{X},
                          x tick label style={rotate=90, anchor=east},
                          scale only axis,
                          ]
                          addplot table[x expr=coordindex,y index=1] {mydata};
                          addplot table[x expr=coordindex,y index=2] {mydata};
                          addplot table[x expr=coordindex,y index=3] {mydata};

                          legend{used,understood,not understood}
                          end{axis}
                          end{tikzpicture}
                          end{document}


                          gives:



                          enter image description here







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 4 at 22:33

























                          answered Mar 4 at 18:51









                          ZarkoZarko

                          127k868166




                          127k868166






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477635%2fhow-to-use-a-mathematical-expression-as-xticklabel%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                              ComboBox Display Member on multiple fields

                              Is it possible to collect Nectar points via Trainline?