Stacked ybar plot creates additional empty y-entries

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
1












I have this code:



documentclassscrartcl

usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma

usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*

begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC

addplot+ table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture

enddocument


The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
additional y entry



Why is this? How can I prevent it?



One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?



Thanks Again!







share|improve this question







New contributor




Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






















    up vote
    4
    down vote

    favorite
    1












    I have this code:



    documentclassscrartcl

    usepackagepgfplots
    pgfplotsset
    compat=1.16,
    table/col sep=comma

    usepackagefilecontents
    beginfilecontents*data.csv
    Type, fillA, fillC, preAllocA, preAllocC
    off, 10, 20, 0, 0
    tree, 4, 5, 6, 4
    computed, 6, 5, 4, 8
    endfilecontents*

    begindocument
    begintikzpicture
    beginaxis[ybar stacked,
    symbolic x coords=off, tree, computed,
    x tick label style=rotate=45,anchor=east]
    legendFillA, FillC, preAllocA, preAllocC

    addplot+ table[y=fillA]data.csv;
    addplot+ table[y=fillC]data.csv;
    addplot+ table[y=preAllocA]data.csv;
    addplot+ table[y=preAllocC]data.csv;
    endaxis
    endtikzpicture

    enddocument


    The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
    additional y entry



    Why is this? How can I prevent it?



    One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?



    Thanks Again!







    share|improve this question







    New contributor




    Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      I have this code:



      documentclassscrartcl

      usepackagepgfplots
      pgfplotsset
      compat=1.16,
      table/col sep=comma

      usepackagefilecontents
      beginfilecontents*data.csv
      Type, fillA, fillC, preAllocA, preAllocC
      off, 10, 20, 0, 0
      tree, 4, 5, 6, 4
      computed, 6, 5, 4, 8
      endfilecontents*

      begindocument
      begintikzpicture
      beginaxis[ybar stacked,
      symbolic x coords=off, tree, computed,
      x tick label style=rotate=45,anchor=east]
      legendFillA, FillC, preAllocA, preAllocC

      addplot+ table[y=fillA]data.csv;
      addplot+ table[y=fillC]data.csv;
      addplot+ table[y=preAllocA]data.csv;
      addplot+ table[y=preAllocC]data.csv;
      endaxis
      endtikzpicture

      enddocument


      The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
      additional y entry



      Why is this? How can I prevent it?



      One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?



      Thanks Again!







      share|improve this question







      New contributor




      Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      I have this code:



      documentclassscrartcl

      usepackagepgfplots
      pgfplotsset
      compat=1.16,
      table/col sep=comma

      usepackagefilecontents
      beginfilecontents*data.csv
      Type, fillA, fillC, preAllocA, preAllocC
      off, 10, 20, 0, 0
      tree, 4, 5, 6, 4
      computed, 6, 5, 4, 8
      endfilecontents*

      begindocument
      begintikzpicture
      beginaxis[ybar stacked,
      symbolic x coords=off, tree, computed,
      x tick label style=rotate=45,anchor=east]
      legendFillA, FillC, preAllocA, preAllocC

      addplot+ table[y=fillA]data.csv;
      addplot+ table[y=fillC]data.csv;
      addplot+ table[y=preAllocA]data.csv;
      addplot+ table[y=preAllocC]data.csv;
      endaxis
      endtikzpicture

      enddocument


      The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
      additional y entry



      Why is this? How can I prevent it?



      One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?



      Thanks Again!









      share|improve this question







      New contributor




      Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Sep 4 at 16:19









      Horus

      1502




      1502




      New contributor




      Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data. See e.g. the examples on p. 97 of the manual.



          documentclassscrartcl

          usepackagepgfplots
          pgfplotsset
          compat=1.16,
          table/col sep=comma

          usepackagefilecontents
          beginfilecontents*data.csv
          Type, fillA, fillC, preAllocA, preAllocC
          off, 10, 20, 0, 0
          tree, 4, 5, 6, 4
          computed, 6, 5, 4, 8
          endfilecontents*

          begindocument
          begintikzpicture
          beginaxis[ybar stacked,
          symbolic x coords=off, tree, computed,
          xtick=data,
          x tick label style=rotate=45,anchor=east]
          legendFillA, FillC, preAllocA, preAllocC

          addplot table[y=fillA]data.csv;
          addplot+ table[y=fillC]data.csv;
          addplot+ table[y=preAllocA]data.csv;
          addplot+ table[y=preAllocC]data.csv;
          endaxis
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer



























            up vote
            3
            down vote













            Answering also the last part, you can set xtick=0,1,2 (I first tried xtick distance=1 which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType to get the ticklabels from the file. Finally, in the plots use x expr to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;.



            enter image description here



            documentclassscrartcl

            usepackagepgfplots
            pgfplotsset
            compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
            table/col sep=comma


            usepackagefilecontents
            beginfilecontents*data.csv
            Type, fillA, fillC, preAllocA, preAllocC
            off, 10, 20, 0, 0
            tree, 4, 5, 6, 4
            computed, 6, 5, 4, 8
            endfilecontents*

            begindocument
            begintikzpicture
            beginaxis[
            ybar stacked,
            xtick=0,1,2, % set explicit tick positions
            xticklabels from table=data.csvType, % get ticklabels from Type column
            x tick label style=rotate=45,anchor=north east, % change east to north east
            % just a quick suggestion for the legend layout
            legend columns=2,
            legend cell align=left,
            legend transposed
            ]
            legendFillA, FillC, preAllocA, preAllocC

            % coordindex corresponds to row number in table, counting from 0
            addplot+ table[x expr=coordindex, y=fillA]data.csv;
            addplot+ table[x expr=coordindex, y=fillC]data.csv;
            addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
            addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
            endaxis
            endtikzpicture

            enddocument





            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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );






              Horus is a new contributor. Be nice, and check out our Code of Conduct.









               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449295%2fstacked-ybar-plot-creates-additional-empty-y-entries%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote



              accepted










              The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data. See e.g. the examples on p. 97 of the manual.



              documentclassscrartcl

              usepackagepgfplots
              pgfplotsset
              compat=1.16,
              table/col sep=comma

              usepackagefilecontents
              beginfilecontents*data.csv
              Type, fillA, fillC, preAllocA, preAllocC
              off, 10, 20, 0, 0
              tree, 4, 5, 6, 4
              computed, 6, 5, 4, 8
              endfilecontents*

              begindocument
              begintikzpicture
              beginaxis[ybar stacked,
              symbolic x coords=off, tree, computed,
              xtick=data,
              x tick label style=rotate=45,anchor=east]
              legendFillA, FillC, preAllocA, preAllocC

              addplot table[y=fillA]data.csv;
              addplot+ table[y=fillC]data.csv;
              addplot+ table[y=preAllocA]data.csv;
              addplot+ table[y=preAllocC]data.csv;
              endaxis
              endtikzpicture
              enddocument


              enter image description here






              share|improve this answer
























                up vote
                3
                down vote



                accepted










                The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data. See e.g. the examples on p. 97 of the manual.



                documentclassscrartcl

                usepackagepgfplots
                pgfplotsset
                compat=1.16,
                table/col sep=comma

                usepackagefilecontents
                beginfilecontents*data.csv
                Type, fillA, fillC, preAllocA, preAllocC
                off, 10, 20, 0, 0
                tree, 4, 5, 6, 4
                computed, 6, 5, 4, 8
                endfilecontents*

                begindocument
                begintikzpicture
                beginaxis[ybar stacked,
                symbolic x coords=off, tree, computed,
                xtick=data,
                x tick label style=rotate=45,anchor=east]
                legendFillA, FillC, preAllocA, preAllocC

                addplot table[y=fillA]data.csv;
                addplot+ table[y=fillC]data.csv;
                addplot+ table[y=preAllocA]data.csv;
                addplot+ table[y=preAllocC]data.csv;
                endaxis
                endtikzpicture
                enddocument


                enter image description here






                share|improve this answer






















                  up vote
                  3
                  down vote



                  accepted







                  up vote
                  3
                  down vote



                  accepted






                  The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data. See e.g. the examples on p. 97 of the manual.



                  documentclassscrartcl

                  usepackagepgfplots
                  pgfplotsset
                  compat=1.16,
                  table/col sep=comma

                  usepackagefilecontents
                  beginfilecontents*data.csv
                  Type, fillA, fillC, preAllocA, preAllocC
                  off, 10, 20, 0, 0
                  tree, 4, 5, 6, 4
                  computed, 6, 5, 4, 8
                  endfilecontents*

                  begindocument
                  begintikzpicture
                  beginaxis[ybar stacked,
                  symbolic x coords=off, tree, computed,
                  xtick=data,
                  x tick label style=rotate=45,anchor=east]
                  legendFillA, FillC, preAllocA, preAllocC

                  addplot table[y=fillA]data.csv;
                  addplot+ table[y=fillC]data.csv;
                  addplot+ table[y=preAllocA]data.csv;
                  addplot+ table[y=preAllocC]data.csv;
                  endaxis
                  endtikzpicture
                  enddocument


                  enter image description here






                  share|improve this answer












                  The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data. See e.g. the examples on p. 97 of the manual.



                  documentclassscrartcl

                  usepackagepgfplots
                  pgfplotsset
                  compat=1.16,
                  table/col sep=comma

                  usepackagefilecontents
                  beginfilecontents*data.csv
                  Type, fillA, fillC, preAllocA, preAllocC
                  off, 10, 20, 0, 0
                  tree, 4, 5, 6, 4
                  computed, 6, 5, 4, 8
                  endfilecontents*

                  begindocument
                  begintikzpicture
                  beginaxis[ybar stacked,
                  symbolic x coords=off, tree, computed,
                  xtick=data,
                  x tick label style=rotate=45,anchor=east]
                  legendFillA, FillC, preAllocA, preAllocC

                  addplot table[y=fillA]data.csv;
                  addplot+ table[y=fillC]data.csv;
                  addplot+ table[y=preAllocA]data.csv;
                  addplot+ table[y=preAllocC]data.csv;
                  endaxis
                  endtikzpicture
                  enddocument


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 4 at 16:35









                  marmot

                  56.4k461123




                  56.4k461123




















                      up vote
                      3
                      down vote













                      Answering also the last part, you can set xtick=0,1,2 (I first tried xtick distance=1 which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType to get the ticklabels from the file. Finally, in the plots use x expr to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;.



                      enter image description here



                      documentclassscrartcl

                      usepackagepgfplots
                      pgfplotsset
                      compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
                      table/col sep=comma


                      usepackagefilecontents
                      beginfilecontents*data.csv
                      Type, fillA, fillC, preAllocA, preAllocC
                      off, 10, 20, 0, 0
                      tree, 4, 5, 6, 4
                      computed, 6, 5, 4, 8
                      endfilecontents*

                      begindocument
                      begintikzpicture
                      beginaxis[
                      ybar stacked,
                      xtick=0,1,2, % set explicit tick positions
                      xticklabels from table=data.csvType, % get ticklabels from Type column
                      x tick label style=rotate=45,anchor=north east, % change east to north east
                      % just a quick suggestion for the legend layout
                      legend columns=2,
                      legend cell align=left,
                      legend transposed
                      ]
                      legendFillA, FillC, preAllocA, preAllocC

                      % coordindex corresponds to row number in table, counting from 0
                      addplot+ table[x expr=coordindex, y=fillA]data.csv;
                      addplot+ table[x expr=coordindex, y=fillC]data.csv;
                      addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
                      addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
                      endaxis
                      endtikzpicture

                      enddocument





                      share|improve this answer
























                        up vote
                        3
                        down vote













                        Answering also the last part, you can set xtick=0,1,2 (I first tried xtick distance=1 which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType to get the ticklabels from the file. Finally, in the plots use x expr to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;.



                        enter image description here



                        documentclassscrartcl

                        usepackagepgfplots
                        pgfplotsset
                        compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
                        table/col sep=comma


                        usepackagefilecontents
                        beginfilecontents*data.csv
                        Type, fillA, fillC, preAllocA, preAllocC
                        off, 10, 20, 0, 0
                        tree, 4, 5, 6, 4
                        computed, 6, 5, 4, 8
                        endfilecontents*

                        begindocument
                        begintikzpicture
                        beginaxis[
                        ybar stacked,
                        xtick=0,1,2, % set explicit tick positions
                        xticklabels from table=data.csvType, % get ticklabels from Type column
                        x tick label style=rotate=45,anchor=north east, % change east to north east
                        % just a quick suggestion for the legend layout
                        legend columns=2,
                        legend cell align=left,
                        legend transposed
                        ]
                        legendFillA, FillC, preAllocA, preAllocC

                        % coordindex corresponds to row number in table, counting from 0
                        addplot+ table[x expr=coordindex, y=fillA]data.csv;
                        addplot+ table[x expr=coordindex, y=fillC]data.csv;
                        addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
                        addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
                        endaxis
                        endtikzpicture

                        enddocument





                        share|improve this answer






















                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          Answering also the last part, you can set xtick=0,1,2 (I first tried xtick distance=1 which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType to get the ticklabels from the file. Finally, in the plots use x expr to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;.



                          enter image description here



                          documentclassscrartcl

                          usepackagepgfplots
                          pgfplotsset
                          compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
                          table/col sep=comma


                          usepackagefilecontents
                          beginfilecontents*data.csv
                          Type, fillA, fillC, preAllocA, preAllocC
                          off, 10, 20, 0, 0
                          tree, 4, 5, 6, 4
                          computed, 6, 5, 4, 8
                          endfilecontents*

                          begindocument
                          begintikzpicture
                          beginaxis[
                          ybar stacked,
                          xtick=0,1,2, % set explicit tick positions
                          xticklabels from table=data.csvType, % get ticklabels from Type column
                          x tick label style=rotate=45,anchor=north east, % change east to north east
                          % just a quick suggestion for the legend layout
                          legend columns=2,
                          legend cell align=left,
                          legend transposed
                          ]
                          legendFillA, FillC, preAllocA, preAllocC

                          % coordindex corresponds to row number in table, counting from 0
                          addplot+ table[x expr=coordindex, y=fillA]data.csv;
                          addplot+ table[x expr=coordindex, y=fillC]data.csv;
                          addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
                          addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
                          endaxis
                          endtikzpicture

                          enddocument





                          share|improve this answer












                          Answering also the last part, you can set xtick=0,1,2 (I first tried xtick distance=1 which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType to get the ticklabels from the file. Finally, in the plots use x expr to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;.



                          enter image description here



                          documentclassscrartcl

                          usepackagepgfplots
                          pgfplotsset
                          compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
                          table/col sep=comma


                          usepackagefilecontents
                          beginfilecontents*data.csv
                          Type, fillA, fillC, preAllocA, preAllocC
                          off, 10, 20, 0, 0
                          tree, 4, 5, 6, 4
                          computed, 6, 5, 4, 8
                          endfilecontents*

                          begindocument
                          begintikzpicture
                          beginaxis[
                          ybar stacked,
                          xtick=0,1,2, % set explicit tick positions
                          xticklabels from table=data.csvType, % get ticklabels from Type column
                          x tick label style=rotate=45,anchor=north east, % change east to north east
                          % just a quick suggestion for the legend layout
                          legend columns=2,
                          legend cell align=left,
                          legend transposed
                          ]
                          legendFillA, FillC, preAllocA, preAllocC

                          % coordindex corresponds to row number in table, counting from 0
                          addplot+ table[x expr=coordindex, y=fillA]data.csv;
                          addplot+ table[x expr=coordindex, y=fillC]data.csv;
                          addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
                          addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
                          endaxis
                          endtikzpicture

                          enddocument






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 4 at 16:48









                          Torbjørn T.

                          150k13242424




                          150k13242424




















                              Horus is a new contributor. Be nice, and check out our Code of Conduct.









                               

                              draft saved


                              draft discarded


















                              Horus is a new contributor. Be nice, and check out our Code of Conduct.












                              Horus is a new contributor. Be nice, and check out our Code of Conduct.











                              Horus is a new contributor. Be nice, and check out our Code of Conduct.













                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449295%2fstacked-ybar-plot-creates-additional-empty-y-entries%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery