legend style customization in pgfplots












2














I have this bar graph, and I want to do 3 things:




  1. Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);

  2. Within the frame of the legend, enter "Data Size" and then the values ​​of 10KB and 20KB;

  3. Change the y-axis value to 28


The code I'm using:



begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords ,
nodes near coords align ={vertical},
]
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
legend{10KB,20KB}
end{axis}
end{tikzpicture}


The graph I have is this:



enter image description here










share|improve this question



























    2














    I have this bar graph, and I want to do 3 things:




    1. Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);

    2. Within the frame of the legend, enter "Data Size" and then the values ​​of 10KB and 20KB;

    3. Change the y-axis value to 28


    The code I'm using:



    begin{tikzpicture}
    begin{axis}[
    ybar,
    enlargelimits=0.3,
    legend style={at={(0.5 ,-0.20)},
    anchor=north,legend columns =-1},
    ylabel ={Memory Usage (KB)},
    xlabel ={Transmissions},
    symbolic x coords ={10,100,250},
    xtick=data,
    nodes near coords ,
    nodes near coords align ={vertical},
    ]
    addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
    addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
    legend{10KB,20KB}
    end{axis}
    end{tikzpicture}


    The graph I have is this:



    enter image description here










    share|improve this question

























      2












      2








      2







      I have this bar graph, and I want to do 3 things:




      1. Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);

      2. Within the frame of the legend, enter "Data Size" and then the values ​​of 10KB and 20KB;

      3. Change the y-axis value to 28


      The code I'm using:



      begin{tikzpicture}
      begin{axis}[
      ybar,
      enlargelimits=0.3,
      legend style={at={(0.5 ,-0.20)},
      anchor=north,legend columns =-1},
      ylabel ={Memory Usage (KB)},
      xlabel ={Transmissions},
      symbolic x coords ={10,100,250},
      xtick=data,
      nodes near coords ,
      nodes near coords align ={vertical},
      ]
      addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
      addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
      legend{10KB,20KB}
      end{axis}
      end{tikzpicture}


      The graph I have is this:



      enter image description here










      share|improve this question













      I have this bar graph, and I want to do 3 things:




      1. Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);

      2. Within the frame of the legend, enter "Data Size" and then the values ​​of 10KB and 20KB;

      3. Change the y-axis value to 28


      The code I'm using:



      begin{tikzpicture}
      begin{axis}[
      ybar,
      enlargelimits=0.3,
      legend style={at={(0.5 ,-0.20)},
      anchor=north,legend columns =-1},
      ylabel ={Memory Usage (KB)},
      xlabel ={Transmissions},
      symbolic x coords ={10,100,250},
      xtick=data,
      nodes near coords ,
      nodes near coords align ={vertical},
      ]
      addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
      addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
      legend{10KB,20KB}
      end{axis}
      end{tikzpicture}


      The graph I have is this:



      enter image description here







      tikz-pgf pgfplots legend






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      Mutante

      223




      223






















          2 Answers
          2






          active

          oldest

          votes


















          3














          documentclass[border = 5pt]{standalone}

          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ymin = 0, ymax = 28,
          ybar,
          enlarge x limits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords align ={vertical},
          ]

          addlegendimage{empty legend}
          addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};

          addlegendentry{Data Size}
          addlegendentry{100KB}
          addlegendentry{20KB}
          %legend{10KB,20KB}
          end{axis}
          end{tikzpicture}
          end{document}



          1. Remove nodes near coords


          2. Use addlegendentry{Data Size}


          3. Set the limit with ymax



          enter image description here






          share|improve this answer























          • But how can i display only one value in the bars? See the answer from @marmot.
            – Mutante
            3 hours ago










          • @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
            – caverac
            3 hours ago










          • Thanks! Now it's perfect!
            – Mutante
            3 hours ago



















          1














          This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords into one.



          documentclass[tikz,border=3.14mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16}
          newcounter{mynodeindex}
          pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
          step nodeindex/.code={stepcounter{mynodeindex}},
          name nodes near coords/.style={
          every node near coord/.append style={/pgfplots/step nodeindex,
          name=#1-themynodeindex,
          alias=#1-last,
          },
          },
          name nodes near coords/.default=coordnode
          }

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ybar,
          enlargelimits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords={},
          nodes near coords align ={vertical},
          name nodes near coords
          ]
          addplot coordinates {(10,28) (100,28) (250,28)};
          addplot coordinates {(10,28) (100,28) (250,28)};
          legend{10KB,20KB}
          end{axis}
          pgfmathtruncatemacro{Xmax}{themynodeindex/2}
          foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
          {path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer





















          • Didn't know about every node near coord, nice! (+1)
            – caverac
            2 hours ago











          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%2f467818%2flegend-style-customization-in-pgfplots%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          documentclass[border = 5pt]{standalone}

          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ymin = 0, ymax = 28,
          ybar,
          enlarge x limits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords align ={vertical},
          ]

          addlegendimage{empty legend}
          addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};

          addlegendentry{Data Size}
          addlegendentry{100KB}
          addlegendentry{20KB}
          %legend{10KB,20KB}
          end{axis}
          end{tikzpicture}
          end{document}



          1. Remove nodes near coords


          2. Use addlegendentry{Data Size}


          3. Set the limit with ymax



          enter image description here






          share|improve this answer























          • But how can i display only one value in the bars? See the answer from @marmot.
            – Mutante
            3 hours ago










          • @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
            – caverac
            3 hours ago










          • Thanks! Now it's perfect!
            – Mutante
            3 hours ago
















          3














          documentclass[border = 5pt]{standalone}

          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ymin = 0, ymax = 28,
          ybar,
          enlarge x limits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords align ={vertical},
          ]

          addlegendimage{empty legend}
          addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};

          addlegendentry{Data Size}
          addlegendentry{100KB}
          addlegendentry{20KB}
          %legend{10KB,20KB}
          end{axis}
          end{tikzpicture}
          end{document}



          1. Remove nodes near coords


          2. Use addlegendentry{Data Size}


          3. Set the limit with ymax



          enter image description here






          share|improve this answer























          • But how can i display only one value in the bars? See the answer from @marmot.
            – Mutante
            3 hours ago










          • @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
            – caverac
            3 hours ago










          • Thanks! Now it's perfect!
            – Mutante
            3 hours ago














          3












          3








          3






          documentclass[border = 5pt]{standalone}

          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ymin = 0, ymax = 28,
          ybar,
          enlarge x limits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords align ={vertical},
          ]

          addlegendimage{empty legend}
          addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};

          addlegendentry{Data Size}
          addlegendentry{100KB}
          addlegendentry{20KB}
          %legend{10KB,20KB}
          end{axis}
          end{tikzpicture}
          end{document}



          1. Remove nodes near coords


          2. Use addlegendentry{Data Size}


          3. Set the limit with ymax



          enter image description here






          share|improve this answer














          documentclass[border = 5pt]{standalone}

          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ymin = 0, ymax = 28,
          ybar,
          enlarge x limits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords align ={vertical},
          ]

          addlegendimage{empty legend}
          addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};

          addlegendentry{Data Size}
          addlegendentry{100KB}
          addlegendentry{20KB}
          %legend{10KB,20KB}
          end{axis}
          end{tikzpicture}
          end{document}



          1. Remove nodes near coords


          2. Use addlegendentry{Data Size}


          3. Set the limit with ymax



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 3 hours ago

























          answered 3 hours ago









          caverac

          5,3581522




          5,3581522












          • But how can i display only one value in the bars? See the answer from @marmot.
            – Mutante
            3 hours ago










          • @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
            – caverac
            3 hours ago










          • Thanks! Now it's perfect!
            – Mutante
            3 hours ago


















          • But how can i display only one value in the bars? See the answer from @marmot.
            – Mutante
            3 hours ago










          • @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
            – caverac
            3 hours ago










          • Thanks! Now it's perfect!
            – Mutante
            3 hours ago
















          But how can i display only one value in the bars? See the answer from @marmot.
          – Mutante
          3 hours ago




          But how can i display only one value in the bars? See the answer from @marmot.
          – Mutante
          3 hours ago












          @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          – caverac
          3 hours ago




          @Mutante Add the option to just one of the plots addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
          – caverac
          3 hours ago












          Thanks! Now it's perfect!
          – Mutante
          3 hours ago




          Thanks! Now it's perfect!
          – Mutante
          3 hours ago











          1














          This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords into one.



          documentclass[tikz,border=3.14mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16}
          newcounter{mynodeindex}
          pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
          step nodeindex/.code={stepcounter{mynodeindex}},
          name nodes near coords/.style={
          every node near coord/.append style={/pgfplots/step nodeindex,
          name=#1-themynodeindex,
          alias=#1-last,
          },
          },
          name nodes near coords/.default=coordnode
          }

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ybar,
          enlargelimits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords={},
          nodes near coords align ={vertical},
          name nodes near coords
          ]
          addplot coordinates {(10,28) (100,28) (250,28)};
          addplot coordinates {(10,28) (100,28) (250,28)};
          legend{10KB,20KB}
          end{axis}
          pgfmathtruncatemacro{Xmax}{themynodeindex/2}
          foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
          {path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer





















          • Didn't know about every node near coord, nice! (+1)
            – caverac
            2 hours ago
















          1














          This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords into one.



          documentclass[tikz,border=3.14mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16}
          newcounter{mynodeindex}
          pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
          step nodeindex/.code={stepcounter{mynodeindex}},
          name nodes near coords/.style={
          every node near coord/.append style={/pgfplots/step nodeindex,
          name=#1-themynodeindex,
          alias=#1-last,
          },
          },
          name nodes near coords/.default=coordnode
          }

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ybar,
          enlargelimits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords={},
          nodes near coords align ={vertical},
          name nodes near coords
          ]
          addplot coordinates {(10,28) (100,28) (250,28)};
          addplot coordinates {(10,28) (100,28) (250,28)};
          legend{10KB,20KB}
          end{axis}
          pgfmathtruncatemacro{Xmax}{themynodeindex/2}
          foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
          {path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer





















          • Didn't know about every node near coord, nice! (+1)
            – caverac
            2 hours ago














          1












          1








          1






          This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords into one.



          documentclass[tikz,border=3.14mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16}
          newcounter{mynodeindex}
          pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
          step nodeindex/.code={stepcounter{mynodeindex}},
          name nodes near coords/.style={
          every node near coord/.append style={/pgfplots/step nodeindex,
          name=#1-themynodeindex,
          alias=#1-last,
          },
          },
          name nodes near coords/.default=coordnode
          }

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ybar,
          enlargelimits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords={},
          nodes near coords align ={vertical},
          name nodes near coords
          ]
          addplot coordinates {(10,28) (100,28) (250,28)};
          addplot coordinates {(10,28) (100,28) (250,28)};
          legend{10KB,20KB}
          end{axis}
          pgfmathtruncatemacro{Xmax}{themynodeindex/2}
          foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
          {path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer












          This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords into one.



          documentclass[tikz,border=3.14mm]{standalone}
          usepackage{pgfplots}
          pgfplotsset{compat=1.16}
          newcounter{mynodeindex}
          pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
          step nodeindex/.code={stepcounter{mynodeindex}},
          name nodes near coords/.style={
          every node near coord/.append style={/pgfplots/step nodeindex,
          name=#1-themynodeindex,
          alias=#1-last,
          },
          },
          name nodes near coords/.default=coordnode
          }

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          ybar,
          enlargelimits=0.3,
          legend style={at={(0.5 ,-0.20)},
          anchor=north,legend columns =-1},
          ylabel ={Memory Usage (KB)},
          xlabel ={Transmissions},
          symbolic x coords ={10,100,250},
          xtick=data,
          nodes near coords={},
          nodes near coords align ={vertical},
          name nodes near coords
          ]
          addplot coordinates {(10,28) (100,28) (250,28)};
          addplot coordinates {(10,28) (100,28) (250,28)};
          legend{10KB,20KB}
          end{axis}
          pgfmathtruncatemacro{Xmax}{themynodeindex/2}
          foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
          {path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
          end{tikzpicture}
          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          marmot

          86.8k499185




          86.8k499185












          • Didn't know about every node near coord, nice! (+1)
            – caverac
            2 hours ago


















          • Didn't know about every node near coord, nice! (+1)
            – caverac
            2 hours ago
















          Didn't know about every node near coord, nice! (+1)
          – caverac
          2 hours ago




          Didn't know about every node near coord, nice! (+1)
          – caverac
          2 hours ago


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f467818%2flegend-style-customization-in-pgfplots%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

          Morgemoulin

          Scott Moir

          Souastre