33

I have a figure in my paper which compared 6 different cases. The figure needs to be in black and white.

In below is the code I used to create the figure.

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}

        \begin{axis}[%
                width=10cm,
                height=4cm,
                scale only axis,
                xmin=1, xmax=3,
                xtick={1,2,3},
                xticklabels={Step1,Step2,Step3},
                xmajorgrids,
                ymin=0.4, ymax=1.2,
                ylabel={$\xi$},
                ymajorgrids,
                title={Stroke Ratio Comparison},
                axis lines*=left,
                line width=1.0pt,
                mark size=2.0pt,
                legend style={at={(1.03,1)},anchor=north west,draw=black,fill=white,align=left}]


                \addplot [
                color=black,
                solid,
                mark=*,
                mark options={solid},
                smooth
                ]
                coordinates{
                 (1,0.941517254116162)(2,0.833049791172753)(3,0.911012408209885) 
                };
                \addlegendentry{$L/D$=2.5};


                \addplot [
                color=black,
                dotted,
                mark=*,
                mark options={solid},
                smooth
                ]
                coordinates{
                 (1,0.848646925806495)(2,0.889383162622147)(3,0.901265846062356) 
                };
                \addlegendentry{$L/D$=3.5};


                \addplot [
                color=black,
                dash pattern=on 1pt off 3pt on 3pt off 3pt,
                mark=*,
                mark options={solid},
                smooth
                ]
                coordinates{
                 (1,0.773775422607358)(2,0.836291579743709)(3,0.91821563038864) 
                };
                \addlegendentry{$L/D$=4.0};


                \addplot [
                color=black,
                dashed,
                mark=*,
                mark options={solid},
                smooth
                ]
                coordinates{
                 (1,0.846412925696005)(2,0.909313371999676)(3,0.916886900310392) 
                };
                \addlegendentry{$L/D$=4.5};


                \addplot [
                color=black,
                dash pattern=on 3pt off 6pt on 6pt off 6pt,
                mark=*,
                mark options={solid},
                smooth
                ]
                coordinates{
                 (1,0.884302757051131)(2,0.941642806394511)(3,0.995341242858434) 
                };
                \addlegendentry{$L/D$=5.0};


                \addplot [
                color=black,
                dotted,
                mark=*,
                mark options={solid},
                smooth
                ]
                coordinates{
                 (1,0.789821315674376)(2,0.981738703732297)(3,1.04121306622012) 
                };
                \addlegendentry{$L/D$=6.0};

        \end{axis}
\end{tikzpicture}%

\end{document}

Here is the result of the compilation.

enter image description here

I would like to have different marker shape such that the figure is easy to understand. Also, as can be seen, the legend does not clearly illustrate the differences between line types. How can I make this more clear to the reader? I would be grateful if I could use other's experiences on creating a professional figure?

45

I think you need to understand differences between \addplot, \addplot[] and \addplot+[] commands. According to pgfplots manual:

The distinction is as follows: \addplot ... (without options) lets pgfplots select colors, markers and linestyles automatically (using cycle list). The variant \addplot+[<option>] ... will use the same automatically determined styles, but in addition it uses <options>. Finally, \addplot[<options>] (without the +) uses only the manually provided <options>.

You use \addplot[...], so you are setting the style for every plot, avoiding predefined styles. You can do this, no problem, but don't use same style (line, color and marker) for every plot. If you look at manual, you'll find how to change markers (square, triangle, star, ...).

But I'd prefer \addplot or \addplot+[] because this way, all predefined styles are used and you don't have to worry about selecting them. The is a predefined cycle list for black and white plots. You can select it with cycle list name=black white.

In next code I've also made some other changes (mainly x and y margins) which can easily forget.

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}

\begin{axis}[
    width=10cm,
   height=4cm,
   scale only axis,
   xmin=0.8, xmax=3.2,
   xtick={1,2,3},
   xticklabels={Step1,Step2,Step3},
   xmajorgrids,
   ymin=0.7, ymax=1.1,
   ylabel={$\xi$},
   ymajorgrids,
   title={Stroke Ratio Comparison},
   axis lines*=left,
%  line width=1.0pt,
%  mark size=2.0pt,
   legend style ={ at={(1.03,1)}, 
        anchor=north west, draw=black, 
        fill=white,align=left},
    cycle list name=black white,
    smooth
]

    \addplot coordinates{
        (1,0.941517254116162)
        (2,0.833049791172753)
        (3,0.911012408209885) 
   };
   \addlegendentry{$L/D$=2.5};

   \addplot coordinates{
      (1,0.848646925806495)
        (2,0.889383162622147)
        (3,0.901265846062356) 
   };
   \addlegendentry{$L/D$=3.5};

   \addplot coordinates{
      (1,0.773775422607358)
        (2,0.836291579743709)
        (3,0.91821563038864) 
   };
   \addlegendentry{$L/D$=4.0};

   \addplot coordinates{
      (1,0.846412925696005)
        (2,0.909313371999676)
        (3,0.916886900310392) 
    };
    \addlegendentry{$L/D$=4.5};

   \addplot coordinates{
        (1,0.884302757051131)
        (2,0.941642806394511)
        (3,0.995341242858434) 
    };
    \addlegendentry{$L/D$=5.0};

    \addplot coordinates{
        (1,0.789821315674376)
        (2,0.981738703732297)
        (3,1.04121306622012) 
    };
    \addlegendentry{$L/D$=6.0};

   \end{axis}
\end{tikzpicture}%
\end{document}

enter image description here

black white cycle list changes marks but only uses solid and dashed lines. If you prefer to use a different line and mark, it's possible to define your own cycle list which it's only a list with line and mark styles. Using next cycle list

\pgfplotscreateplotcyclelist{my black white}{%
solid, every mark/.append style={solid, fill=gray}, mark=*\\%
dotted, every mark/.append style={solid, fill=gray}, mark=square*\\%
densely dotted, every mark/.append style={solid, fill=gray}, mark=otimes*\\%
loosely dotted, every mark/.append style={solid, fill=gray}, mark=triangle*\\%
dashed, every mark/.append style={solid, fill=gray},mark=diamond*\\%
loosely dashed, every mark/.append style={solid, fill=gray},mark=*\\%
densely dashed, every mark/.append style={solid, fill=gray},mark=square*\\%
dashdotted, every mark/.append style={solid, fill=gray},mark=otimes*\\%
dashdotdotted, every mark/.append style={solid},mark=star\\%
densely dashdotted,every mark/.append style={solid, fill=gray},mark=diamond*\\%
}

you will get:

enter image description here

  • Thank you very much for your excellent explanation. How can I also cycle through the line types? – AFP Sep 21 '13 at 20:39
  • @Ahm, your welcome. About changing also line styles, please look at the updated answer. – Ignasi Sep 22 '13 at 19:22
  • Relevant typo: dasdotdotted -> dashdotdotted (can't edit it) – PHPirate May 9 '18 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.