How to use addplot with “draw = none” and marks?

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











up vote
3
down vote

favorite












I would like to record a plot's style to the legend without actually drawing the plot.



I know how to do this when the plot style does not have marks, as shown in the first example below.



However, when the plot has marks, as in the second example, the marks still get drawn even though draw=none.



Is there anyway to suppress the marks, while still ensuring that the style gets propagated to the legend? If not, any suggested workarounds?



MWE:



documentclass[article]standalone

usepackagetikz
usepackagepgfplots
pgfplotssetcompat = newest % loads newest improved settings

begindocument

begintikzpicture

beginaxis

% Use draw=none so that the plot is not drawn, but style is recorded to
% legend entry
addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
addlegendentryfirst plot

% Would like to do the same thing with a mark
% But the mark still gets drawn!
addplot [blue, mark=*, domain=0:3.5, draw=none] 15 - .5*x;
addlegendentrysecond plot

endaxis
endtikzpicture
enddocument


This produces:



enter image description here



What I want is a blank plot with just the legend.







share|improve this question
























    up vote
    3
    down vote

    favorite












    I would like to record a plot's style to the legend without actually drawing the plot.



    I know how to do this when the plot style does not have marks, as shown in the first example below.



    However, when the plot has marks, as in the second example, the marks still get drawn even though draw=none.



    Is there anyway to suppress the marks, while still ensuring that the style gets propagated to the legend? If not, any suggested workarounds?



    MWE:



    documentclass[article]standalone

    usepackagetikz
    usepackagepgfplots
    pgfplotssetcompat = newest % loads newest improved settings

    begindocument

    begintikzpicture

    beginaxis

    % Use draw=none so that the plot is not drawn, but style is recorded to
    % legend entry
    addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
    addlegendentryfirst plot

    % Would like to do the same thing with a mark
    % But the mark still gets drawn!
    addplot [blue, mark=*, domain=0:3.5, draw=none] 15 - .5*x;
    addlegendentrysecond plot

    endaxis
    endtikzpicture
    enddocument


    This produces:



    enter image description here



    What I want is a blank plot with just the legend.







    share|improve this question






















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I would like to record a plot's style to the legend without actually drawing the plot.



      I know how to do this when the plot style does not have marks, as shown in the first example below.



      However, when the plot has marks, as in the second example, the marks still get drawn even though draw=none.



      Is there anyway to suppress the marks, while still ensuring that the style gets propagated to the legend? If not, any suggested workarounds?



      MWE:



      documentclass[article]standalone

      usepackagetikz
      usepackagepgfplots
      pgfplotssetcompat = newest % loads newest improved settings

      begindocument

      begintikzpicture

      beginaxis

      % Use draw=none so that the plot is not drawn, but style is recorded to
      % legend entry
      addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
      addlegendentryfirst plot

      % Would like to do the same thing with a mark
      % But the mark still gets drawn!
      addplot [blue, mark=*, domain=0:3.5, draw=none] 15 - .5*x;
      addlegendentrysecond plot

      endaxis
      endtikzpicture
      enddocument


      This produces:



      enter image description here



      What I want is a blank plot with just the legend.







      share|improve this question












      I would like to record a plot's style to the legend without actually drawing the plot.



      I know how to do this when the plot style does not have marks, as shown in the first example below.



      However, when the plot has marks, as in the second example, the marks still get drawn even though draw=none.



      Is there anyway to suppress the marks, while still ensuring that the style gets propagated to the legend? If not, any suggested workarounds?



      MWE:



      documentclass[article]standalone

      usepackagetikz
      usepackagepgfplots
      pgfplotssetcompat = newest % loads newest improved settings

      begindocument

      begintikzpicture

      beginaxis

      % Use draw=none so that the plot is not drawn, but style is recorded to
      % legend entry
      addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
      addlegendentryfirst plot

      % Would like to do the same thing with a mark
      % But the mark still gets drawn!
      addplot [blue, mark=*, domain=0:3.5, draw=none] 15 - .5*x;
      addlegendentrysecond plot

      endaxis
      endtikzpicture
      enddocument


      This produces:



      enter image description here



      What I want is a blank plot with just the legend.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 21 at 19:18









      evencoil

      224137




      224137




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You can use addlegendimage (in combination with addlegendentry) to achieve what you want. Just give the option or key--values respectively to the commands argument as you would do to addplot. Please note that at least one addplot command is present so that the legend shows up.



          % used PGFPlots v1.16
          documentclass[border=5pt]standalone
          usepackagepgfplots
          begindocument
          begintikzpicture
          beginaxis

          addlegendimageno markers,red
          addlegendentryfirst plot
          addlegendimageblue,mark=*,only marks
          addlegendentrysecond plot

          addplot [draw=none] x;

          endaxis
          endtikzpicture
          enddocument


          image showing the result of above code






          share|improve this answer



























            up vote
            2
            down vote













            If you are willing to cheat, you could set xmin=0 and just plot samples at=-1. I stress that this is a cheat, and of course won't work if you wan to use that empty plot for intersections or fillbetween or the like.



            documentclass[article]standalone

            usepackagetikz
            usepackagepgfplots
            pgfplotssetcompat = newest % loads newest improved settings

            begindocument

            begintikzpicture

            beginaxis[xmin=0,xmax=3.5]

            % Use draw=none so that the plot is not drawn, but style is recorded to
            % legend entry
            addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
            addlegendentryfirst plot

            % Would like to do the same thing with a mark
            % But the mark still gets drawn!
            %beginscope[opacity=0]
            addplot [blue, mark=*, draw=none,samples at=-1] 15 - .5*x;
            %endscope
            %tikzsetopacity=1
            addlegendentrysecond plot

            endaxis
            endtikzpicture
            enddocument


            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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f447046%2fhow-to-use-addplot-with-draw-none-and-marks%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
              4
              down vote



              accepted










              You can use addlegendimage (in combination with addlegendentry) to achieve what you want. Just give the option or key--values respectively to the commands argument as you would do to addplot. Please note that at least one addplot command is present so that the legend shows up.



              % used PGFPlots v1.16
              documentclass[border=5pt]standalone
              usepackagepgfplots
              begindocument
              begintikzpicture
              beginaxis

              addlegendimageno markers,red
              addlegendentryfirst plot
              addlegendimageblue,mark=*,only marks
              addlegendentrysecond plot

              addplot [draw=none] x;

              endaxis
              endtikzpicture
              enddocument


              image showing the result of above code






              share|improve this answer
























                up vote
                4
                down vote



                accepted










                You can use addlegendimage (in combination with addlegendentry) to achieve what you want. Just give the option or key--values respectively to the commands argument as you would do to addplot. Please note that at least one addplot command is present so that the legend shows up.



                % used PGFPlots v1.16
                documentclass[border=5pt]standalone
                usepackagepgfplots
                begindocument
                begintikzpicture
                beginaxis

                addlegendimageno markers,red
                addlegendentryfirst plot
                addlegendimageblue,mark=*,only marks
                addlegendentrysecond plot

                addplot [draw=none] x;

                endaxis
                endtikzpicture
                enddocument


                image showing the result of above code






                share|improve this answer






















                  up vote
                  4
                  down vote



                  accepted







                  up vote
                  4
                  down vote



                  accepted






                  You can use addlegendimage (in combination with addlegendentry) to achieve what you want. Just give the option or key--values respectively to the commands argument as you would do to addplot. Please note that at least one addplot command is present so that the legend shows up.



                  % used PGFPlots v1.16
                  documentclass[border=5pt]standalone
                  usepackagepgfplots
                  begindocument
                  begintikzpicture
                  beginaxis

                  addlegendimageno markers,red
                  addlegendentryfirst plot
                  addlegendimageblue,mark=*,only marks
                  addlegendentrysecond plot

                  addplot [draw=none] x;

                  endaxis
                  endtikzpicture
                  enddocument


                  image showing the result of above code






                  share|improve this answer












                  You can use addlegendimage (in combination with addlegendentry) to achieve what you want. Just give the option or key--values respectively to the commands argument as you would do to addplot. Please note that at least one addplot command is present so that the legend shows up.



                  % used PGFPlots v1.16
                  documentclass[border=5pt]standalone
                  usepackagepgfplots
                  begindocument
                  begintikzpicture
                  beginaxis

                  addlegendimageno markers,red
                  addlegendentryfirst plot
                  addlegendimageblue,mark=*,only marks
                  addlegendentrysecond plot

                  addplot [draw=none] x;

                  endaxis
                  endtikzpicture
                  enddocument


                  image showing the result of above code







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 21 at 19:45









                  Stefan Pinnow

                  18.7k83170




                  18.7k83170




















                      up vote
                      2
                      down vote













                      If you are willing to cheat, you could set xmin=0 and just plot samples at=-1. I stress that this is a cheat, and of course won't work if you wan to use that empty plot for intersections or fillbetween or the like.



                      documentclass[article]standalone

                      usepackagetikz
                      usepackagepgfplots
                      pgfplotssetcompat = newest % loads newest improved settings

                      begindocument

                      begintikzpicture

                      beginaxis[xmin=0,xmax=3.5]

                      % Use draw=none so that the plot is not drawn, but style is recorded to
                      % legend entry
                      addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
                      addlegendentryfirst plot

                      % Would like to do the same thing with a mark
                      % But the mark still gets drawn!
                      %beginscope[opacity=0]
                      addplot [blue, mark=*, draw=none,samples at=-1] 15 - .5*x;
                      %endscope
                      %tikzsetopacity=1
                      addlegendentrysecond plot

                      endaxis
                      endtikzpicture
                      enddocument


                      enter image description here






                      share|improve this answer
























                        up vote
                        2
                        down vote













                        If you are willing to cheat, you could set xmin=0 and just plot samples at=-1. I stress that this is a cheat, and of course won't work if you wan to use that empty plot for intersections or fillbetween or the like.



                        documentclass[article]standalone

                        usepackagetikz
                        usepackagepgfplots
                        pgfplotssetcompat = newest % loads newest improved settings

                        begindocument

                        begintikzpicture

                        beginaxis[xmin=0,xmax=3.5]

                        % Use draw=none so that the plot is not drawn, but style is recorded to
                        % legend entry
                        addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
                        addlegendentryfirst plot

                        % Would like to do the same thing with a mark
                        % But the mark still gets drawn!
                        %beginscope[opacity=0]
                        addplot [blue, mark=*, draw=none,samples at=-1] 15 - .5*x;
                        %endscope
                        %tikzsetopacity=1
                        addlegendentrysecond plot

                        endaxis
                        endtikzpicture
                        enddocument


                        enter image description here






                        share|improve this answer






















                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          If you are willing to cheat, you could set xmin=0 and just plot samples at=-1. I stress that this is a cheat, and of course won't work if you wan to use that empty plot for intersections or fillbetween or the like.



                          documentclass[article]standalone

                          usepackagetikz
                          usepackagepgfplots
                          pgfplotssetcompat = newest % loads newest improved settings

                          begindocument

                          begintikzpicture

                          beginaxis[xmin=0,xmax=3.5]

                          % Use draw=none so that the plot is not drawn, but style is recorded to
                          % legend entry
                          addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
                          addlegendentryfirst plot

                          % Would like to do the same thing with a mark
                          % But the mark still gets drawn!
                          %beginscope[opacity=0]
                          addplot [blue, mark=*, draw=none,samples at=-1] 15 - .5*x;
                          %endscope
                          %tikzsetopacity=1
                          addlegendentrysecond plot

                          endaxis
                          endtikzpicture
                          enddocument


                          enter image description here






                          share|improve this answer












                          If you are willing to cheat, you could set xmin=0 and just plot samples at=-1. I stress that this is a cheat, and of course won't work if you wan to use that empty plot for intersections or fillbetween or the like.



                          documentclass[article]standalone

                          usepackagetikz
                          usepackagepgfplots
                          pgfplotssetcompat = newest % loads newest improved settings

                          begindocument

                          begintikzpicture

                          beginaxis[xmin=0,xmax=3.5]

                          % Use draw=none so that the plot is not drawn, but style is recorded to
                          % legend entry
                          addplot [red, domain=0:3.5, draw=none] 25*x^0.2;
                          addlegendentryfirst plot

                          % Would like to do the same thing with a mark
                          % But the mark still gets drawn!
                          %beginscope[opacity=0]
                          addplot [blue, mark=*, draw=none,samples at=-1] 15 - .5*x;
                          %endscope
                          %tikzsetopacity=1
                          addlegendentrysecond plot

                          endaxis
                          endtikzpicture
                          enddocument


                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 21 at 19:41









                          marmot

                          55.4k460121




                          55.4k460121



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f447046%2fhow-to-use-addplot-with-draw-none-and-marks%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