折线图 pgfplots 缩放不正确

折线图 pgfplots 缩放不正确

不知道该怎么做才能修复缩放问题。反正我也不是专家

\documentclass[12pt,oneside]{book}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\pgfplotstableread[row sep=\\,col sep=&]{
interval        & osc\\
0-20   &   0.036577203\\
20-40  &   0.043723048\\
40-60  &   0.05056666\\
60-80  &   0.058321928\\
80-100 &   0.058026387\\
100-120&   0.065174919\\
120-140&   0.069114037\\
140-160&   0.076558998\\
160-180&   0.080510575\\
180-200&   0.341889141\\
200-220&   0.317810041\\
220-240&   0.36893627\\
240-260&   0.371424858\\
260-280&   0.411409229\\
280-300&   0.395096262\\
300-320&   0.419199066\\
320-340&   0.411609599\\
}\sixipd


\begin{tikzpicture}
\begin{axis}[
    axis x line*=bottom,
    symbolic x coords={0-20,20-40,40-60,60-80,80-100,100-120,120-140,140-160,160-180,180-200,200-220,220-240,240-260,260-280,280-300,300-320,320-340},
    major tick length=0cm,
    xtick = data,
    ymin=0, ymax=0.5,
    enlarge y limits={upper,value=0.2},
    ytick={0,01, 0.05,0.1,0.2,0.5},
    ymajorgrids=true,
    legend style={at={(0.5,1)},
    anchor=north,legend columns=-1},
    every node near coord/.append style={rotate=90, anchor=west},
    bar width = 17pt,
]
    \addplot table[x=interval,y=osc]{\sixipd};
\end{axis}
\end{tikzpicture}
\end{document}

答案1

你应该旋转x标签:

在此处输入图片描述

也不清楚,如果你喜欢有bar情节......

\documentclass[12pt,oneside]{book}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15} % <---

\begin{document}
\pgfplotstableread[row sep=\\,col sep=&]{
interval        & osc\\
0-20   &   0.036577203\\
20-40  &   0.043723048\\
40-60  &   0.05056666\\
60-80  &   0.058321928\\
80-100 &   0.058026387\\
100-120&   0.065174919\\
120-140&   0.069114037\\
140-160&   0.076558998\\
160-180&   0.080510575\\
180-200&   0.341889141\\
200-220&   0.317810041\\
220-240&   0.36893627\\
240-260&   0.371424858\\
260-280&   0.411409229\\
280-300&   0.395096262\\
300-320&   0.419199066\\
320-340&   0.411609599\\
}\sixipd


\begin{tikzpicture}
\begin{axis}[
    width=0.8\linewidth, %<--
    axis x line*=bottom,
    symbolic x coords={0-20,20-40,40-60,60-80,80-100,100-120,120-140,140-160,160-180,180-200,200-220,220-240,240-260,260-280,280-300,300-320,320-340},
    major tick length=0cm,
    xtick = data,
    xticklabel style = {rotate=90, anchor=east}, %<---
    ymin=0, ymax=0.5,
    enlarge y limits={upper,value=0.2},
    ytick={0,01, 0.05,0.1,0.2,0.5},
    ymajorgrids=true,
    legend style={at={(0.5,1)},
    anchor=north,legend columns=-1},
    every node near coord/.append style={rotate=90, anchor=west},
%    bar width = 17pt,
]
    \addplot table[x=interval,y=osc]{\sixipd};
\end{axis}
\end{tikzpicture}
\end{document}

您可以使用数据表获得类似的结果,而无需写间隔:

    \documentclass[12pt,oneside]{book}
    \usepackage{tikz}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.15}

    \begin{document}
    \pgfplotstableread[row sep=\\,col sep=&]{
    interval        & osc\\
0   &   0.036577203\\
20  &   0.043723048\\
40  &   0.05056666\\
60  &   0.058321928\\
80  &   0.058026387\\
100 &   0.065174919\\
120 &   0.069114037\\
140 &   0.076558998\\
160 &   0.080510575\\
180 &   0.341889141\\
200 &   0.317810041\\
220 &   0.36893627\\
240 &   0.371424858\\
260 &   0.411409229\\
280 &   0.395096262\\
300 &   0.419199066\\
320 &   0.411609599\\
    }\sixipd
    \begin{tikzpicture}
\begin{axis}[
    width=0.8\linewidth,                        % <---
    axis x line*=bottom,
    xtick=data,                                 % <---
    xticklabel interval boundaries,             % <---
    x tick label style={rotate=90,anchor=east}, % <---
%
    ymin=0, ymax=0.55,
    ytick={0,01, 0.05,0.1,0.2,0.5},
    ymajorgrids=true,
            ]
    \addplot table {\sixipd};
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容