Latex pgfplots do not show dots in my plot

1.2k views Asked by At

I am trying to make a plot which meant to be looking like this

I used overleaf as my editing tool
It works when I separate it in a clear file without any other things
But when I combine it with other things in my project, it turned out to look like this

Here is the .tex file

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.15} 
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    ytick={0,0.05,0.1,0.15,0.2,0.25,0.3,0.35},
    xtick={0,50,100},
    xmax=100,
    xmin=0,
    ymax=0.35,
    ymin=0,
    ylabel=Maximum value of p,
    xlabel= Group size n,
    height=6cm,
    width=10cm,
    /pgf/number format/fixed,
    /pgf/number format/precision=3,
    domain=0:100
    ]
\addplot[scatter,scatter src=]
table {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}

Here's the things in the .dat file

x y      
2 0.292893
3 0.306639
4 0.292893
5 0.275220
6 0.258164
7 0.242693
8 0.228895
9 0.216619
10 0.205672
11 0.195867
12 0.187042
13 0.179059
14 0.171803
15 0.165178
16 0.159104
17 0.153512
18 0.148347
19 0.143560
20 0.139108
21 0.134958
22 0.131078
23 0.127442
24 0.124026
25 0.120811
26 0.117778
27 0.114912
28 0.112199
29 0.109626
30 0.107183
31 0.104859
32 0.102645
33 0.100535
34 0.098519
35 0.096592
36 0.094748
37 0.092981
38 0.091287
39 0.089660
40 0.088097
41 0.086594
42 0.085147
43 0.083753
44 0.082410
45 0.081113
46 0.079862
47 0.078653
48 0.077483
49 0.076353
50 0.075258
51 0.074198
52 0.073170
53 0.072174
54 0.071208
55 0.070270
56 0.069359
57 0.068474
58 0.067613
59 0.066777
60 0.065963
61 0.065171
62 0.064399
63 0.063648
64 0.062916
65 0.062203
66 0.061507
67 0.060828
68 0.060166
69 0.059519
70 0.058888
71 0.058271
72 0.057668
73 0.057080
74 0.056504
75 0.055941
76 0.055390
77 0.054851
78 0.054324
79 0.053808
80 0.053302
81 0.052807
82 0.052322
83 0.051847
84 0.051381
85 0.050924
86 0.050476
87 0.050037
88 0.049606
89 0.049183
90 0.048769
91 0.048361
92 0.047962
93 0.047569
94 0.047183
95 0.046805
96 0.046433
97 0.046067
98 0.045708
99 0.045355
100 0.04500

Is there any problem in my tex? How can I fix it?
Or is there any other ways to plot graphs like this in Latex?

1

There are 1 answers

0
samcarter_is_at_topanswers.xyz On BEST ANSWER

The syntax scatter src= is wrong and I'm not sure why you use the scatter option.

Here a plot with blue markers instead:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.15} 

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    ytick={0,0.05,0.1,0.15,0.2,0.25,0.3,0.35},
    xtick={0,50,100},
    xmax=100,
    xmin=0,
    ymax=0.35,
    ymin=0,
    ylabel=Maximum value of p,
    xlabel= Group size n,
    height=6cm,
    width=10cm,
    /pgf/number format/fixed,
    /pgf/number format/precision=3,
    domain=0:100
    ]
\addplot[mark=*,blue]
table {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here