1

I add 4 legend to my graph and different types of mark. Also, I want the legends to be under the X axis and in one line to each other. Position of legend Also How I can to write caption of this graph: Figure 1. Growth of different types foodborne pathogens.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=24,
%xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},
xtick={0,4,8,12,24}, %%%<------------- here
xlabel=\ {Time},
ymin=0,
ymax=10,
ytick={0,1,2,3,4,5,6,7,8,9,10},
yticklabels={0,1,2,3,4,5,6,7,8,9,10},
ylabel=\ {log(Cfu/cm$^{2}$)},
y axis line style={black},
ytick style={black},
yticklabel style={black},
axis x line*=bottom,
axis y line*=left,    
tick align = outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 5\\
4 5\\
8 9.8\\
12 8.8\\
24 8.62\\};
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 2\\
4 3\\
8 4.8\\
12 7.8\\
24 8.162\\};
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=halfdiamond*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 3\\
4 1\\
8 2.8\\
12 2.8\\
24 2.162\\};
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=triangle*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 4\\
4 3.3\\
8 5.8\\
12 5.7\\
24 6.162\\};
\legend {$Staphylococcus\ aureus$, $Escherichia\ coli$,$Listeria\ monocytogenes$,$Campylobacter\ jejuni$}
\end{axis}
\end{tikzpicture}%

\end{document}

enter image description here

Also, Figure end only one dot, Thank you

4

The Plots with Standard Caption

Something like this? I've included code to display the legend in one line but I've commented it because I'm not sure that is really what you mean. (It looks silly to me as the legend is then much wider than the plots!

\documentclass{article}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=newest}
\begin{document}

\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
      color=black,
      scale only axis,
      xmin=0,
      xmax=24,
      %xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},
      xtick={0,4,8,12,24}, %%%<------------- here
      xlabel=\ {Time},
      ymin=0,
      ymax=10,
      ytick={0,1,2,3,4,5,6,7,8,9,10},
      yticklabels={0,1,2,3,4,5,6,7,8,9,10},
      ylabel=\ {log(Cfu/cm$^{2}$)},
      y axis line style={black},
      ytick style={black},
      yticklabel style={black},
      axis x line*=bottom,
      axis y line*=left,
      tick align = outside,
      every axis legend/.append style={
        at = {(.5,-.2)},
        anchor = north,
%       legend columns=-1, % to display legends in one line but do you really want this?
        legend cell align = left,
        draw = none,
        legend columns = 2,
      },
    ]
      \addplot [
        color=black,
        solid,
        line width=0.5pt,
        mark size=2.5pt,
        mark size=2.5pt,
        mark=square*,
        mark options={solid,fill=white}
      ]
      table[row sep=crcr]{
        0 5\\
        4 5\\
        8 9.8\\
        12 8.8\\
        24 8.62\\};
      \addplot [
        color=black,
        solid,
        line width=0.5pt,
        mark size=2.5pt,
        mark size=2.5pt,
        mark=*,
        mark options={solid,fill=white}]
      table[row sep=crcr]{
        0 2\\
        4 3\\
        8 4.8\\
        12 7.8\\
        24 8.162\\};
      \addplot [
        color=black,
        solid,
        line width=0.5pt,
        mark size=2.5pt,
        mark size=2.5pt,
        mark=halfdiamond*,
        mark options={solid,fill=white}]
      table[row sep=crcr]{
        0 3\\
        4 1\\
        8 2.8\\
        12 2.8\\
        24 2.162\\};
      \addplot [
        color=black,
        solid,
        line width=0.5pt,
        mark size=2.5pt,
        mark size=2.5pt,
        mark=triangle*,
        mark options={solid,fill=white}]
      table[row sep=crcr]{
        0 4\\
        4 3.3\\
        8 5.8\\
        12 5.7\\
        24 6.162\\};
      \legend {$Staphylococcus\ aureus$, $Escherichia\ coli$,$Listeria\ monocytogenes$,$Campylobacter\ jejuni$}
    \end{axis}
  \end{tikzpicture}
  \caption{Growth of different types foodborne pathogens.}
\end{figure}

\end{document}

adjusted legend and added caption

Formatting the Caption

Based on Andreas Wallner's answer, adding

\usepackage{caption}
  \DeclareCaptionLabelSeparator{fullstop}{.\quad}
  \captionsetup[figure]{labelsep=fullstop}

to your preamble will modify the formatting of figure captions accordingly:

caption adjustment

Adjusting the Size

You can adjust the size of your plots using

\pgfplotsset{width=120mm}

adjusted plot size on page

  • Thank you very much dear, Only one small question- how do legends will be 2 name legend and inside 2 name of legend, without black border total legends – user67733 Dec 14 '14 at 20:44
  • @user67733 Sorry, but what do you mean by 'do legends will be 2 name legend and inside 2 name of legend'? – cfr Dec 14 '14 at 20:54
  • @user67733 You can add draw = none, legend columns = 2, to the legend style if you don't want the border and you want 2 columns. Is that what you mean? – cfr Dec 14 '14 at 20:56
  • I send hand-draw photoshop picture – user67733 Dec 14 '14 at 21:02
  • @user67733 The code I just suggested will do that. Just add those lines to modify the legend style. – cfr Dec 14 '14 at 21:07

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.