我可以在同一页上(实际上是同一张图片中)放置多个箱线图,但垂直方向的直方图不能超过 2 个,水平方向的直方图只能超过 1 个。如何调整直方图的大小并设置每条水平线上可以容纳的数量?也许一对应该放在一个段落中?这种格式有标准样式建议吗?
理想情况下,我希望每行并排显示 2 个直方图,每页显示 6 行。这样,我每页就能看到 6 个月的舒张压和收缩压读数。我希望能够确定自两年前心脏病发作以来每日血压读数的趋势,并向医生咨询。
数据文件是一列数字:
151
103
118
...
148
用于创建直方图的 tex 只是从 pgfplots 手册中提取出来的,有几行我不明白,但它运行得很好:
\begin{tikzpicture}
\begin{axis} [
title={September 2016},
ybar interval, % I don't think I need this line
xtick=, % I don't think I need this either
xticklabel= % I think this just gives a nicer font
{$ [ \pgfmathprintnumber\tick,%
\pgfmathprintnumber\nexttick)$}
]]
\addplot+[hist={data=x, bins=100}]
file {"c:/Documents and Settings/Dad/Desktop/bloodPressure/histsystolic_September2016.txt"};
\end{axis}
\end{tikzpicture}
非常感谢您的帮助。
答案1
所以您的意思是下面这样?
(我只是在这里绘制随机数据,因为您自己没有提供合适的数据。)
\documentclass[paper=A4,pagesize]{scrartcl}
\usepackage{pgfplots}
\usetikzlibrary{
% use `groupplots' library to easily put plots next to each other
pgfplots.groupplots,
}
\pgfplotsset{
% define a style which should be used for the plots
my addplot style/.style={
hist,
},
}
% just needed to know where the text area boundaries are
\usepackage{tikzpagenodes}
\begin{document}
% this `tikzpicture' is just to know where the text area boundaries are
\begin{tikzpicture}[remember picture,overlay]
\draw [draw=red]
(current page text area.north west)
rectangle (current page text area.south east);
\end{tikzpicture}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=2 by 6,
xticklabels at=edge bottom,
yticklabels at=edge left,
% adjust these two values depending on page and text area size
% (together with `width' and `height')
vertical sep=12.5mm,
horizontal sep=5mm,
},
% adjust these two values depending on page and text area size
% (together with `vertical sep' and `horizontal sep')
width=0.425\textwidth,
height=0.1\textheight,
scale only axis,
ybar interval, % I don't think I need this line
xtick=, % I don't think I need this either
xticklabel={%
$[\pgfmathprintnumber\tick,\pgfmathprintnumber\nexttick)$%,
},
]
\nextgroupplot[title={January 2016 systolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={January 2016 diastolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={February 2016 systolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={February 2016 diastolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={March 2016 systolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={March 2016 diastolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={April 2016 systolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={April 2016 diastolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={May 2016 systolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={May 2016 diastolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={June 2016 systolic}]
\addplot+ [my addplot style] {rnd};
\nextgroupplot[title={June 2016 diastolic}]
\addplot+ [my addplot style] {rnd};
\end{groupplot}
\end{tikzpicture}
\end{document}