为什么 Tikzplot 对许多数据绘制重叠图?

为什么 Tikzplot 对许多数据绘制重叠图?

当我使用 tikzpicture 绘制以下数据时,图形看起来不太好看。代码在这里:

  \begin{filecontents*}{data.dat}
X   P   $Q_B$   $Q_C$   $Q_D$   $Q_E$
1   A1  0.2500  0.2500  0.5000  0.5000
2   A2  0.1667  0.1250  0.5000  0.5000
3   A3  0.1250  0.1250  0.1250  0.1250
4   A4  0.0833  0.0156  0.1250  0.2500
5   A5  0.0417  0.0005  0.0625  0.1667
6   A6  0.0250  0.0000  0.0313  0.1250
7   A7  0.0250  0.0002  0.0156  0.1250
8   A8  0.0125  0.0000  0.0010  0.0625
9   A9  0.1250  0.0625  0.2500  0.2500
11  A10 0.0833  0.0156  0.2500  0.2500
12  A11 0.0625  0.0039  0.2500  0.2500
13  A12 0.0417  0.0020  0.0625  0.2500
14  A13 0.0208  0.0000  0.0313  0.0833
15  A14 0.0625  0.0156  0.1250  0.1250
16  A15 0.0208  0.0002  0.0313  0.0625
17  A16 0.0078  0.0000  0.0039  0.0313
\end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.3}
\begin{document}
 \begin{tikzpicture}[xscale=0.7,yscale=0.3]
\begin{axis}[
    xlabel=Q Series,
    ylabel=P Values,
    %width=10cm,
  ymajorgrids=true,
  xmajorgrids=true,
  grid style=dashed,
    xtick=data,
    xtick = {1,...,20},
    ytick={0,0.1,0.2,...,0.6},
    xticklabels from table={data.dat}{P},
  ]
        \addplot [blue,thick,mark=square*] table [
        x=X,
%            % this worked so far, ...
 %            y=$Q_B$,
                % ... but now we have to use this and it works
        y expr=\thisrow{$Q_B$},
        ]{data.dat};
            \addlegendentry{$Q_B$ series}
        \addplot [red,thick,mark=square*] table [
           x=X,
           y expr=\thisrow{$Q_C$},
        ]{data.dat};
           \addlegendentry{$Q_C$ series}
        \addplot [black,dashed,thick,mark=square*] table [
           x=X,
        y expr=\thisrow{$Q_D$},
        ]{data.dat};
          \addlegendentry{$Q_D$ series}
         \addplot [black,dashed,thick,mark=square*] table [
     x=X,
   y expr=\thisrow{$Q_E$},
   ]{data.dat};
   \addlegendentry{$Q_E$ series}
     \end{axis}
  \end{tikzpicture}
  \end{document}     

生成如下图表:
enter image description here

但我需要以下清晰美观的图表:

enter image description here

第二张图是用 Libreoffice 生成的,如何用 Latex 生成?

答案1

enter image description here

与您的 MWE 相比,变化以 标记% <--。主要变化:(i) 缩放标记,(ii) 减小字体大小至\tiny,(iii) 确定图形宽度,(iV) 删除图片缩放。

  \begin{filecontents*}{data.dat}
X   P   $Q_B$   $Q_C$   $Q_D$   $Q_E$
1   A1  0.2500  0.2500  0.5000  0.5000
2   A2  0.1667  0.1250  0.5000  0.5000
3   A3  0.1250  0.1250  0.1250  0.1250
4   A4  0.0833  0.0156  0.1250  0.2500
5   A5  0.0417  0.0005  0.0625  0.1667
6   A6  0.0250  0.0000  0.0313  0.1250
7   A7  0.0250  0.0002  0.0156  0.1250
8   A8  0.0125  0.0000  0.0010  0.0625
9   A9  0.1250  0.0625  0.2500  0.2500
10  A10 0.0833  0.0156  0.2500  0.2500
11  A11 0.0625  0.0039  0.2500  0.2500
12  A12 0.0417  0.0020  0.0625  0.2500
13  A13 0.0208  0.0000  0.0313  0.0833
14  A14 0.0625  0.0156  0.1250  0.1250
15  A15 0.0208  0.0002  0.0313  0.0625
16  A16 0.0078  0.0000  0.0039  0.0313
\end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.3}
\begin{document}
 \begin{tikzpicture}%[xscale=0.7,yscale=0.3] <-- deleted
\begin{axis}[
width=0.8\linewidth, height=0.5\linewidth, % <-- added
    xlabel=Q Series,
    ylabel=P Values,
  ymajorgrids=true,
  xmajorgrids=true,
  grid style=dashed,
    xtick=data,
    xmin=1, xmax=16,    % <-- added
    xtick = {1,...,16},
    ytick={0,0.1,0.2,...,0.6},
    xticklabels from table={data.dat}{P},
    font=\tiny,% <-- added
    mark options={solid, draw, scale=0.4},% <-- added
                ]
\addplot[blue,mark=square*] table [x=X, y expr=\thisrow{$Q_B$},
        ] {data.dat};
\addplot [red,mark=square*] table [x=X, y expr=\thisrow{$Q_C$},
        ] {data.dat};
\addplot[black,dashed,mark=square*] table [x=X,y expr=\thisrow{$Q_D$},
        ] {data.dat};
\addplot[black,dashed,mark=square*] table [x=X,y expr=\thisrow{$Q_E$},
        ] {data.dat};
\legend{$Q_B$ series, $Q_C$ series, $Q_D$ series, $Q_E$ series}
     \end{axis}
  \end{tikzpicture}
  \end{document}

相关内容