2

For the code given below, when I plot my data, it displays like this:

enter image description here

This incorrect, the display should look like this:

enter image description here

Can you tell me what is the issue here?

Here is my code:

 \documentclass[border=4mm]{standalone}
 \usepackage{pgfplots}
 \usepackage{tikz}

 \usetikzlibrary{
        fit,
        shapes,
        pgfplots.groupplots,
    }
 \pgfplotsset{compat=newest}
\begin{filecontents*}{FIT_costsens.txt}
1   0.055   0.348
2   0.123   0.565
3   0.110   0.304
4   0.068   0.609
5   0.137   0.435
6   0.096   0.304
7   0.110   0.261
8   0.082   0.522
9   0.123   0.435
10  0.123   0.435
100 0.192 0.217
\end{filecontents*}


\begin{document}
\newcommand{\plotcompAdaBstJfe}{FIT_costsens.txt}
\begin{tikzpicture}
\begin{axis}[width=14cm,height=9cm,
                legend pos=north east,
                xlabel={Ratio},
                ylabel={(\%)},
                %ymax=30,
                ymin=0,
                smooth,
                y tick label style={
                /pgf/number format/.cd,
                fixed,
                fixed zerofill,
                precision=3,
                /tikz/.cd
    },
                grid=both,
                every major grid/.style={gray, opacity=0.5}]
\addplot [line width=1.6pt,
            mark=none,
            mark options={scale=.65}]%
            table[x index=0,y index=1,col sep=space] {\plotcompAdaBstJfe};
            \addlegendentry{Type I};
\addplot [line width=1.6pt,
            mark=none,
            red,
            mark options={scale=.65}]%
            table[x index=0,y index=2,col sep=space] {\plotcompAdaBstJfe};
            \addlegendentry{Type II};
\end{axis}
\end{tikzpicture}

\end{document}
4
  • 1
    Given the large gap, you might not want to use smooth here
    – daleif
    Commented Oct 2, 2023 at 13:54
  • @daleif, thanks for your response. I do have the plot set to smooth (line 35)?, however the problem persists. Thanks!
    – Joe
    Commented Oct 2, 2023 at 13:59
  • 1
    Removing smooth from axis fixed it for me. BTW, col sep=space is default. Commented Oct 2, 2023 at 14:17
  • 1
    As I wrote: you might NOT want to use smooth here
    – daleif
    Commented Oct 2, 2023 at 14:23

1 Answer 1

2
  • your problem is solved by @daleif comment
  • after cleanup you diagram code (see @ John Kormylo comment) and a bit rearranged axis and \addplot options I got your desired result:

enter image description here

\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\newcommand{\plotcompAdaBstJfe}{FIT_costsens.txt}
 
\begin{filecontents*}{FIT_costsens.txt}
1   0.055   0.348
2   0.123   0.565
3   0.110   0.304
4   0.068   0.609
5   0.137   0.435
6   0.096   0.304
7   0.110   0.261
8   0.082   0.522
9   0.123   0.435
10  0.123   0.435
100 0.192 0.217
\end{filecontents*}


\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    width=14cm, height=9cm,
    grid=both,
    xlabel={Ratio},
    ylabel={(\%)},
    legend pos=north east,
    ymin=0,
    yticklabel style={/pgf/number format/.cd,
                       fixed,
                       fixed zerofill,
                       precision=3,
                        },
    no marks,
every axis plot post/.append style={line width=1.6pt},
                ]

\addplot    table[x index=0,y index=1] {\plotcompAdaBstJfe};
\addlegendentry{Type I};

\addplot    table[x index=0,y index=2] {\plotcompAdaBstJfe};
\addlegendentry{Type II};
\end{axis}
    \end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .