I want to crop the top part of the ternary plot given below at x = 0.7 because I don't have any datapoints in that region and want to save space. How can I do this?
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{ternary}
\begin{document}
\begin{tikzpicture}
\begin{ternaryaxis}[
ternary limits relative=false,
xlabel= x,
ylabel= y,
zlabel= z,
width=9.5cm,
height=9.5cm,
xmin=0.3,
xmax=1,
ymin=0,
ymax=0.7,
zmin=0,
zmax=0.7,
clip=false,
disabledatascaling,
]
\addplot3[only marks, mark options={black}]
table {
0.63 0.37 0
0.43 0.57 0
0.56 0 0.44
0.57 0.1 0.33
0.40 0.35 0.25
0.45 0.31 0.24
};
\end{ternaryaxis}
\end{tikzpicture}
\end{document}
Best Answer
Jakes suggestion
First you need to find out what region to paint over in white. This is best done in the axis coordinate system, which you can use via
(axis cs:<coordinate>)
. This is a little strange, as the x-axis is the one pointing in 120° direction while the y-axis points in 240° direction. However it is quite possible to define e.g. the following path:Which will lead to the following output:
Next, you'll need to reset the current boundin box and create a new one. This has to be done outside of the axis environment, so unfortunately you won't be able to use the axis coordinate system any more. Fortunately, for the last axis environment a node named
current axis
is defined. The normal anchors likesouth east
only contain the plot but not the labels. However there are special anchors likeouter south west
which you can use. As not the whole plot area is needed, you can use the calc library for computations with coordinates. So the linesput after the axis environment will yield
which look quite good yet. However, the upper edge is gray and only half width as you just painted over it, so you'll have to draw it again via
\draw (axis cs: 0.7,0.3) -- (axis cs:0.7,0.0);
. Furthermore the upper edge does not have any ticks, and I don't know how to let pgfplots draw some there.Code
Output
Full manual approach
Doing the whole plot has the advantage that you can influence everything just the way you like it, but the disadvantage that it only has the features you provided, and it may take a while to make this reusable. Here's an idea that might be a starting point:
Set up the x-axis in 0° direction and the y axis in 60° direction.
Clip the drawing area and draw the triangular grid.
Draw the outline of the plot.
Draw the data points. Only the x- and z-components were used, as y is not independant of them.
Set up parameters to print math numbers with one digit precision
Draw the tick lines and label them, also for the upper edge of the plot.
Draw nodes for the axis labels.
Just some helper nodes to show a few coordinates.
Code
Output