有没有关于如何编写 Bagnouls–Gaussen 生物气候图(温度图)的示例?这里有一张图: http://www.sciencedirect.com/science/article/pii/S0379711210000949
温度的标度一般标在左边,降水的标度一般为右边的一半。
答案1
PGFPlots 可以使用两个axis
相互叠加的环境来实现这一点。通过使用样式,您可以非常高效地生成这些图表。一旦定义了样式precipitation
和temperature
,您只需输入
\begin{tikzpicture}
\pgfplotstableread{
Month Precipitation Temperature
1 65 7
2 55 8
3 45 10
4 33 15
5 12 20
6 8 24
7 12 27
8 3 26
9 12 22
10 65 17
11 50 12
12 91 8
}\data
\begin{axis}[precipitation]
\addplot table {\data} \cycleplot;
\end{axis}
\begin{axis}[temperature]
\addplot table {\data} \cycleplot;
\end{axis}
\end{tikzpicture}
得到以下图表(请注意,我还定义了一个新\cycleplot
命令,将图表“继续”到左侧和右侧,以便更清楚地看到周期性):
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.7}
\pgfplotsset{
precipitation/.style={
ymin=0, ymax=#1,
scale only axis,
cycle list={
black, mark=*\\
},
table/x=Month,
table/y=Precipitation,
axis y line*=left,
xtick={1,...,12},
xticklabels={Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec},
enlarge x limits={abs=0.5},
execute at end plot={\label{precipplot}},
ylabel=\ref{precipplot} Precipitation in mm
},
precipitiation/.default=100,
temperature/.style={
ymin=0, ymax=#1,
scale only axis,
cycle list={
gray, thick, mark=square*\\
},
table/x=Month,
table/y=Temperature,
axis y line*=right,
hide x axis,
enlarge x limits={abs=0.5},
execute at end plot={\label{tempplot}},
ylabel=\ref{tempplot} Temperature in C
},
temperature/.default=50
}
\newcommand\cycleplot{
(current plot end|-current plot begin) ++(axis direction cs:1,0) -- (current plot end)
(current plot begin|-current plot end) ++(axis direction cs:-1,0) -- (current plot begin)
}
\pgfplotsset{
width=10cm,
height=6cm
}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
Month Precipitation Temperature
1 65 7
2 55 8
3 45 10
4 33 15
5 12 20
6 8 24
7 12 27
8 3 26
9 12 22
10 65 17
11 50 12
12 91 8
}\data
\begin{axis}[precipitation]
\addplot table {\data} \cycleplot;
\end{axis}
\begin{axis}[temperature]
\addplot table {\data} \cycleplot;
\end{axis}
\end{tikzpicture}
\end{document}
填充温度曲线高于降水曲线的区域需要一些技巧:您可以先绘制温度曲线并填充其下方的整个区域,然后在其上方绘制降水曲线,用白色填充其下方的区域。不幸的是,这也会覆盖温度曲线(而不仅仅是填充的区域),因此您必须再次绘制降水曲线(这次不进行填充):
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.7}
\usetikzlibrary{calc}
\pgfplotsset{
precipitation/.style={
axis on top,
ymin=0, ymax=#1,
scale only axis,
cycle list={
black, mark=*,fill=white, mark options={fill=black}\\
},
table/x=Month,
table/y=Precipitation,
axis y line*=left,
xtick={1,...,12},
xticklabels={Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec},
enlarge x limits={abs=0.5},
execute at end plot={\label{precipplot}},
ylabel=\ref{precipplot} Precipitation in mm
},
precipitiation/.default=100,
temperature/.style={
ymin=0, ymax=#1,
scale only axis,
cycle list={
gray, thick, mark=square*\\
},
table/x=Month,
table/y=Temperature,
axis y line*=right,
hide x axis,
enlarge x limits={abs=0.5},
execute at end plot={\label{tempplot}},
ylabel=\ref{tempplot} Temperature in C
},
temperature/.default=50
}
\newcommand\cycleplot{
-- ($(current plot end|-current plot begin)+(axis direction cs:1,0)$) |- (rel axis cs:-0.1,-0.1)
-- ($(current plot begin|-current plot end)+(axis direction cs:-1,0)$) -- (current plot begin)
}
\pgfplotsset{
width=10cm,
height=6cm
}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
Month Precipitation Temperature
1 65 7
2 55 8
3 45 10
4 33 15
5 12 20
6 8 24
7 12 27
8 3 26
9 12 22
10 65 17
11 50 12
12 91 8
}\data
\pgfplotsset{set layers=axis on top}
\begin{axis}[temperature, hide axis]
\addplot [draw=none,fill=gray!25] table {\data} \cycleplot;
\end{axis}
\begin{axis}[precipitation]
\addplot table {\data} \cycleplot;
\end{axis}
\begin{axis}[temperature]
\addplot table {\data} \cycleplot;
\node at (rel axis cs:0.55,0.28) {Dry season};
\end{axis}
\end{tikzpicture}
\end{document}