Shade and insert labels in a triangular region with TikZ
Here is my solution:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{shadings}
\begin{document}
\begin{tikzpicture}
\draw[top color=white,bottom color=red] (0,0) -- (1,2) -- (0,3) -- cycle;
\foreach \coordinate/\label/\pos in {{(0,0)/label1/above left},{(1,2)/label2/right},{(0,3)/label3/above right}}
\node[\pos] at \coordinate {\label};
\draw[->] (-5.0,0) -- (5.0,0) node[right] {$x$} coordinate(x axis);
\draw[->] (0,-5.0) -- (0,5.0) node[above] {$y$} coordinate(y axis);
\end{tikzpicture}
\end{document}
It gives:
The key points are basically two:
the
foreach
that allows to specify in one shot thecoordinate
(i.e. (0,0)) in which thelabel
will be placed in a givenposition
(i.e.above left
);the use of the
shadings
library that allows to shade the region; in the example the shading is vertical, but it is possible to insert different type of shadings (see 47 Shadings Library from the pgfmanual version April 25, 2012 / 46 Shadings Library from the pgfmanual version October 25, 2010).
A solution with tikz and tkz-euclide
\documentclass[11pt]{scrartcl}
\usepackage{tkz-euclide}
\usetkzobj{polygons}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=5,ymax=5]
\tkzAxeXY
\tkzDefPoint(0,0){A}
\tkzDefPoint(1,2){B}
\tkzDefPoint(0,3){C}
\tkzDrawPolygon[top color=white,bottom color=red](A,B,C)
\tkzLabelPoints[above right](A,B,C)
\end{tikzpicture}
\end{document}
Here is an example using the patch
plot type of pgfplots:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[patch,shader=interp]
table[point meta=\thisrow{c}] {
x y c
% first patch:
0 0 0.2
1 1 0
2 0 1
% second patch:
1 1 0
2 0 -1
3 1 0
% third patch:
2 0 0.5
3 1 1
4 0 0.5
};
\end{axis}
\end{tikzpicture}
\end{document}
and with labels and continuos shading:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[patch,shader=interp]
table[point meta=\thisrow{c}] {
x y c
% first patch:
0 0 0.2
1 1 0
2 0 1
% second patch:
1 1 0
2 0 1
3 1 0
% third patch:
2 0 1
3 1 0
4 0 0.5
};
\addplot[only marks,nodes near coords] % this produces labels
table[point meta=explicit symbolic,meta=labels] {
x y labels
0 0 $a$
1 1 $b$
2 0 $c$
3 1 $d$
4 0 $e$
};
\end{axis}
\end{tikzpicture}
\end{document}
It uses a default axis configuration and reads points from an input table. The table has three columns: one for x, one for y, and one for the color data. The color data is mapped linearly into a colormap
which can be configured, what you see is the default. The shader=interp
tells pgfplots to produce a linear shading between the three corners and is color data.
The second graphics has two plots in the same axis: one which produces the geometry and one which produces nodes near coords
. This is a special scatter plot which assumes that point meta
contains the content of nodes which are placed at the input coordinates. In this case, I used point meta=explicit symbolic
which, for table input, means that the meta
column contains textual data. I chose meta=labels
to idenfity the "labels" column which contains math mode text.
You may also be interested in
axis lines=left
which does not produce a box but axis lines on their lower ("left") limits,three dimensional plots with
\addplot3
(and one more table column)other input formats (coordinates as in your example is also supported, even with color data)
details for the encountered options + more examples in the pdf manual on http://pgfplots.sourceforge.net/