我是这里的新手。我需要你的帮助:
我需要排版这条曲线 仅使用 Tikz 和 pgf,不使用 pstricks。要绘制的 xy 值包含在此表的第 3 列和第 4 列中:
注意:我已经看到了此相关示例中的代码,但我更喜欢非整数 x 刻度: 如何从原始数据文件绘制累积频率? 但这对我来说没用,因为我想避免 pstricks,因为它与我的文档中的某些代码冲突。
我将非常感激。
答案1
可以让 pgfplots 积累数据,例如https://tex.stackexchange.com/a/198397。对于虚线,可以使用交点。对于百分比,可以使用图的最后一点。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.17}
\newcounter{ihor}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=12cm,
tick align=outside,tick pos=lower,
xtick={9,19,...,99},xticklabel=\empty,
minor tick style={draw=none},x tick style={draw=none},
extra x ticks={9.5,19.5,...,99.5},
extra x tick style={draw,grid style={draw=none},x tick style={draw},
xticklabel=\pgfmathprintnumber\tick,
xticklabel style={rotate=30}},
axis x line=bottom,axis y line=left,
xmin=9,xmax=100,xlabel=Marks,
ymin=0,ymax=55,minor tick num=4,ylabel=Cumulative frequency,
grid=both,grid style={cyan},minor grid style={help lines,cyan},
table/create on use/cumulative frequency/.style={% cf. https://tex.stackexchange.com/a/198397
create col/expr={\pgfmathaccuma + \thisrow{frequency}}
}]
\addplot[red,thick,name path global=plot,smooth,mark=+,mark options={color=black}]
table [x expr=9.5+10*\coordindex,
y=cumulative frequency]{
frequency
2
3
4
6
13
10
5
3
2
2
} coordinate[pos=1](pmax);
\path (0,0) coordinate (O)
(100,0) coordinate (br) (100,\pgfkeysvalueof{/pgfplots/ymax}) coordinate
(tr);
\setcounter{ihor}{0}
\pgfplotsinvokeforeach{12.75,25.5,38.25}{%
\stepcounter{ihor}
\edef\temp{\noexpand\path[name path=hor-\number\value{ihor}]
(\pgfkeysvalueof{/pgfplots/xmin},#1) -- (\pgfkeysvalueof{/pgfplots/xmax},#1);
\noexpand\draw[dashed,name intersections={of=plot and hor-\number\value{ihor},
by=i-\number\value{ihor}}]
(i-\number\value{ihor}|-O) \ifnum\value{ihor}=1
node[above left]{$Q_{\arabic{ihor}}$}
\else
node[above right]{$Q_{\arabic{ihor}}$}
\fi
|- (i-\number\value{ihor}-|O);}
\temp
}
\path (br) -- (pmax) coordinate[pos=0.4] (p40);
\path[name path=hor] (p40) -- (p40-|O);
\draw[dashed,name intersections={of=plot and hor,by=i}]
(br|-i) -| (br-|i) (i);
\end{axis}
\draw[-stealth] (br) -- (tr);
\path (br) -- (br|-pmax) foreach \X in {0,20,...,100}
{coordinate[pos=\X/100] (p\X)
(p\X) edge[help lines]++ (\pgfkeysvalueof{/pgfplots/minor tick length},0)
node[pos=\X/100,right,xshift=\pgfkeysvalueof{/pgfplots/minor tick length}] {\X\%} };
\end{tikzpicture}
\end{document}