Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there any example how to code a Bagnouls–Gaussen bioclimatic diagram (ombrothermic diagram)? There is one diagram here: http://www.sciencedirect.com/science/article/pii/S0379711210000949

The scale of the temperatures is generally indicated on the left. It is generally half of the scale of precipitations, indicated on the right.

share|improve this question
2  
See if tex.stackexchange.com/questions/21975/… helps. –  Torbjørn T. Feb 25 '13 at 19:05
    
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. –  tohecz Feb 25 '13 at 19:11
add comment

1 Answer 1

PGFPlots can do this, using two axis environments that are positioned on top of each other. By using styles, you can very efficiently generate these charts. Once the styles precipitation and temperature have been defined, all you need to type is

\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}

to get the following plot (note that I've also defined a new \cycleplot command that "continues" the plots to the left and right so the periodicity can be seen more clearly):

\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}

Filling the area where the temperature curve is above the precipitation curve takes a bit of trickery: You can first draw the temperature curve and fill the whole area underneath it, then draw the precipitation curve on top, filling the area underneath it with white. Unfortunately, this will also draw over the temperature curve (not just the filled area), so you'll have to draw the precipitation curve again (this time without filling):

\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}
share|improve this answer
    
I add an \addlegendentry{precipitation} and \addlegendentry{temperature} but the two legend items are overlapped. –  Leonidas Liakos Feb 25 '13 at 20:11
    
@LeonidasLiakos: I edited my answer. Would something like that work for you? –  Jake Feb 25 '13 at 21:05
    
Yes it's very useful. Is it possible to add some fill color between the two curves and a label for it? Like that: docsdrive.com/images/medwelljournals/javaa/2010/… –  Leonidas Liakos Feb 26 '13 at 15:02
    
@LeonidasLiakos: It's possible, it's just a bit of a hassle. I've edited my answer –  Jake Feb 26 '13 at 21:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.