1

This question already has an answer here:

I would like labeling as follows:
enter image description here

It does not get proper labeling on y-axis when I am plotting data from CSV file in Latex. Here is the code :

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.8}


\begin{document}
\pgfkeys{/pgf/number format/.cd,1000 sep={\,}}
\begin{tikzpicture}
\begin{axis}[ 
%restrict x to domain=1:4,
restrict y to domain=7:8, %ymax=8,ymin=7
xtick={1,2,3,4},
%ytick={7.90,7.91,...,7.99,8},
xlabel=Shares, ylabel=Entropy]


\addplot[color=red,mark=*, mark size=1.5pt] table[x=Share_No., y=Entropy_r, col sep=tab]{data.csv};
\addplot[color=green,mark=square*, mark size=1.5pt] table[x=Share_No., y=Entropy_g, col sep=tab]{data.csv};
\addplot[color=blue,mark=triangle*, mark size=1.5pt] table[x=Share_No., y=Entropy_b, col sep=tab]{data.csv};
\legend{red,green, blue}
 \end{axis} 
 \end{tikzpicture}
\end{document}

and the CSV file :

Share_No.   Entropy_r   Entropy_g   Entropy_b
1   7.9981486429    7.99831760161   7.99844751811
2   7.99870797699   7.99858499663   7.99867850346
3   7.99883018839   7.99864575932   7.99835839694
4   7.99851352793   7.99834080804   7.99864899695

It produces the following graph:

enter image description here

How can I fix this?

Updated: The answer in the given link is not working for me. Here are the modified codes:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.8}


\begin{document}
\pgfkeys{/pgf/number format/.cd,1000 sep={\,}}
\begin{tikzpicture}
\begin{axis}[ 
    y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=1,
    /tikz/.cd
},

%restrict x to domain=1:4,
%restrict y to domain=7:8, %ymax=8,ymin=7
xtick={1,2,3,4},
%ytick={7.90,7.91,...,7.99,8},
xlabel=Shares, ylabel=Entropy]

\addplot[color=red,mark=*, mark size=1.5pt] table[x=Share_No., y=Entropy_r, col sep=tab]{data.csv};
\addplot[color=green,mark=square*, mark size=1.5pt] table[x=Share_No., y=Entropy_g, col sep=tab]{data.csv};
\addplot[color=blue,mark=triangle*, mark size=1.5pt] table[x=Share_No., y=Entropy_b, col sep=tab]{data.csv};
\legend{red,green, blue}
 \end{axis} 
 \end{tikzpicture}
\end{document}

marked as duplicate by TeXnician, Phelype Oleinik, Stefan Pinnow pgfplots Dec 27 '18 at 12:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @engineer The answer in the given ling is not working. I have tried with this code. – MKS Dec 27 '18 at 9:26
  • Not working is unfortunately no measurable criterion. Could you please be more specific what does not work? Otherwise, this seems to be a duplicate… – TeXnician Dec 27 '18 at 9:46
  • @TeXnician I have added the modified code. – MKS Dec 27 '18 at 9:54
1

The answer linked to works just fine, but you didn't set the closing ] correctly (after your post's update you introduced a \par within the options which is causing another error).

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.8}

\begin{filecontents*}{data.csv}
Share_No.   Entropy_r   Entropy_g   Entropy_b
1   7.9981486429    7.99831760161   7.99844751811
2   7.99870797699   7.99858499663   7.99867850346
3   7.99883018839   7.99864575932   7.99835839694
4   7.99851352793   7.99834080804   7.99864899695
\end{filecontents*}

\begin{document}
\pgfkeys{/pgf/number format/.cd,1000 sep={\,}}
\begin{tikzpicture}
\begin{axis}[ 
%restrict x to domain=1:4,
%restrict y to domain=7:8, %ymax=8,ymin=7
xtick={1,2,3,4},
%ytick={7.90,7.91,...,7.99,8},
xlabel=Shares, ylabel=Entropy,
    y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=3,
    /tikz/.cd
}]
\addplot[color=red,mark=*, mark size=1.5pt] table[x=Share_No., y=Entropy_r, col sep=space]{data.csv};
\addplot[color=green,mark=square*, mark size=1.5pt] table[x=Share_No., y=Entropy_g, col sep=space]{data.csv};
\addplot[color=blue,mark=triangle*, mark size=1.5pt] table[x=Share_No., y=Entropy_b, col sep=space]{data.csv};
\legend{red,green, blue}
 \end{axis} 
 \end{tikzpicture}
\end{document}

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