我正在尝试重现 USDA 土壤三角。为此,我需要翻转默认 pgfplots-ternary 的 x 轴和 y 轴。
我了解,我可以切换我的输入(真的不想这样做),但我也需要改变方向,而我甚至没有成功。
在默认的三元轴中,y 轴在左侧,x 轴在右侧,x 从 0(右下)到 100(顶部),y 从顶部到左下。但是,根据 USDA 土壤三角区,x 需要从左下到顶部,y 需要从顶部到右下,z 从右下到左下。
此外,x 轴(和刻度)需要水平(与 z 轴平行),而 y 轴需要与 x 轴平行,z 轴应该与 y 轴平行。
我尝试了x dir=reverse
和axis on top
命令,因为我认为我可以简单地翻转我的坐标,但没有成功。有没有人遇到过类似的问题或知道答案?
()
我尽力获取了所有数据等。以下是我得到的:
\documentclass[]{standalone}
\usepackage[dvipsnames]{xcolor} % color handling
\usepackage{tikz} % draw pictures and diagrams
\usepackage{pgfplots} % proper plotting
\usepackage{file contents} % writing reading of data files
\usepgfplotslibrary{ternary, units}
\begin{filecontents*}{USDASoils.csv}
name,clay,silt,sand
Sand,0,0,100
Sand,10,0,90
Sand,0,15,85
Loamy Sand,0,15,85
Loamy Sand,10,0,90
Loamy Sand,15,0,85
Loamy Sand,0,30,70
Clay,55,0,45
Clay,100,0,0
Clay,60,40,0
Clay,40,40,20
Clay,40,15,45
Sandy Clay,35,0,65
Sandy Clay,55,0,45
Sandy Clay,35,20,45
Silty Clay,40,40,20
Silty Clay,60,40,0
Silty Clay,40,60,0
Loam,8,40,52
Loam,20,27,53
Loam,27,28,45
Loam,27,50,23
Loam,8,50,42
Sandy Loam,0,30,70
Sandy Loam,15,0,85
Sandy Loam,20,0,80
Sandy Loam,20,27,53
Sandy Loam,8,40,52
Sandy Loam,8,50,42
Sandy Loam,0,50,50
Clay Loam,27,28,45
Clay Loam,40,15,45
Clay Loam,40,40,20
Clay Loam,27,53,20
Sandy Clay Loam,20,0,80
Sandy Clay Loam,35,0,65
Sandy Clay Loam,35,20,45
Sandy Clay Loam,27,28,45
Sandy Clay Loam,20,27,53
Silty Loam,0,50,50
Silty Loam,27,50,23
Silty Loam,27,73,0
Silty Loam,13,87,0
Silty Loam,13,80,7
Silty Loam,0,80,20
Silty Clay Loam,27,53,20
Silty Clay Loam,40,40,20
Silty Clay Loam,40,60,0
Silty Clay Loam,27,73,0
Silt,0,80,20
Silt,13,80,7
Silt,13,87,0
Silt,0,100,0
\end{filecontents*}
\pgfplotsset{
discard if not/.style 2 args={
x filter/.code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\else
\def\pgfmathresult{inf}
\fi
}
}
}
\begin{document}
\begin{tikzpicture}[scale=0.9]
\begin{ternaryaxis}[
xmax=100,
ymax=100,
zmax=100,
ternary limits relative,
xlabel=x (Clay),
ylabel=y (Silt),
zlabel=z (Sand),
xtick={0,10,...,100},
ytick={0,10,...,100},
ztick={0,10,...,100},
minor tick num=1,
grid=both,
]
\def\myopacity{0.5}
% Sands
\addplot3 [fill=yellow, fill opacity=\myopacity, discard if not={name}{Sand}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Melon, fill opacity=\myopacity,discard if not={name}{Loamy Sand}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
% Sand Text
\node at (axis cs:3,5,) {\tiny Sand};
\node at (axis cs:5,13) {\tiny Loamy};
\node at (axis cs:2,18) {\tiny Sand};
% Clays
\addplot3 [fill=yellow, fill opacity=\myopacity, discard if not={name}{Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=red, fill opacity=\myopacity, discard if not={name}{Sandy Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Aquamarine!50, fill opacity=\myopacity, discard if not={name}{Silty Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
%Clay Text
\node at (axis cs:65,16) {\tiny Clay};
\node at (axis cs:43,6) {\tiny Sandy};
\node at (axis cs:38,8) {\tiny Clay};
\node at (axis cs:48,47) {\tiny Silty};
\node at (axis cs:44,49) {\tiny Clay};
% Loams
\addplot3 [fill=brown, fill opacity=\myopacity, discard if not={name}{Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=purple!50, fill opacity=\myopacity, discard if not={name}{Sandy Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=purple!25, fill opacity=\myopacity, discard if not={name}{Sandy Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=SpringGreen, fill opacity=\myopacity, discard if not={name}{Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Green, fill opacity=\myopacity, discard if not={name}{Silty Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Aquamarine, fill opacity=\myopacity, discard if not={name}{Silty Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
% Loams Text
\node at (axis cs:19,40) {\tiny Loam};
\node at (axis cs:12,23) {\tiny Sandy Loam};
\node at (axis cs:28,13) {\tiny Sandy Clay Loam};
\node at (axis cs:33,35) {\tiny Clay Loam};
\node at (axis cs:13,65) {\tiny Silty Loam};
\node at (axis cs:36,55) {\tiny Silty};
\node at (axis cs:31,58) {\tiny Clay Loam};
% Silts
\addplot3 [fill=green, fill opacity=\myopacity, discard if not={name}{Silt}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
% Silt Text
\node at (axis cs:6,88) {\tiny Silt};
\end{ternaryaxis}
\end{tikzpicture}
\end{document}
看起来像这样:
我对我的结果非常满意,但我想:
1)切换轴(如上所述),
2)删除小刻度(但保留小网格 - 我无法让它工作),并且
3)使轴标签沿三角形边倾斜(如上图所示)