解决方案
R有一个外部的软件包叫做 VCD 应该做你想要什么。
的文档是非常好(122页的手册分布式瓦特/包);这里还有一本书同名,定量信息的视觉显示的,由包的作者(教授迈克尔友善)。
要使用的 VCD 下,只需要调用的 ternaryplot() 并通过在MX 3矩阵,即,矩阵具有三个创建三元图列。
的方法,签名非常简单;只有一个参数(米×3数据矩阵)是必需的;和所有的关键字参数涉及到的情节的美学,除了规模,其中,当设置为1,归一化数据逐列。
要在三元相图绘制的数据点,对于给定的点的坐标被计算为质点的重心其中包括数据矩阵的每个特征值是一个单独的重量,因此,点V的坐标(A,b,c)是
V(b, c/2, c * (3^.5)/2
要生成在下图中,我刚创建一些假数据来表示四种不同的化学混合物,各由三种物质(X,Y,Z)变化的馏分。我缩放输入(所以X + Y + Z = 1),但如果你在它的“缩放”参数的值传递给函数会为你做它(事实上,默认的是1,我相信这是你的问题需要)。我用不同的颜色和符号来表示的四个数据点,但也可以只使用一个单一的颜色/符号和标记的每个点(通过“ID”参数)。
其他提示
创建用于生成三元(或更多)的曲线的非常基本的脚本。无网格线或ticklines,但那些不会太硬的“基础”阵列中使用的载体的补充。
from pylab import *
def ternaryPlot(
data,
# Scale data for ternary plot (i.e. a + b + c = 1)
scaling=True,
# Direction of first vertex.
start_angle=90,
# Orient labels perpendicular to vertices.
rotate_labels=True,
# Labels for vertices.
labels=('one','two','three'),
# Can accomodate more than 3 dimensions if desired.
sides=3,
# Offset for label from vertex (percent of distance from origin).
label_offset=0.10,
# Any matplotlib keyword args for plots.
edge_args={'color':'black','linewidth':2},
# Any matplotlib keyword args for figures.
fig_args = {'figsize':(8,8),'facecolor':'white','edgecolor':'white'},
):
'''
This will create a basic "ternary" plot (or quaternary, etc.)
'''
basis = array(
[
[
cos(2*_*pi/sides + start_angle*pi/180),
sin(2*_*pi/sides + start_angle*pi/180)
]
for _ in range(sides)
]
)
# If data is Nxsides, newdata is Nx2.
if scaling:
# Scales data for you.
newdata = dot((data.T / data.sum(-1)).T,basis)
else:
# Assumes data already sums to 1.
newdata = dot(data,basis)
fig = figure(**fig_args)
ax = fig.add_subplot(111)
for i,l in enumerate(labels):
if i >= sides:
break
x = basis[i,0]
y = basis[i,1]
if rotate_labels:
angle = 180*arctan(y/x)/pi + 90
if angle > 90 and angle <= 270:
angle = mod(angle + 180,360)
else:
angle = 0
ax.text(
x*(1 + label_offset),
y*(1 + label_offset),
l,
horizontalalignment='center',
verticalalignment='center',
rotation=angle
)
# Clear normal matplotlib axes graphics.
ax.set_xticks(())
ax.set_yticks(())
ax.set_frame_on(False)
# Plot border
ax.plot(
[basis[_,0] for _ in range(sides) + [0,]],
[basis[_,1] for _ in range(sides) + [0,]],
**edge_args
)
return newdata,ax
if __name__ == '__main__':
k = 0.5
s = 1000
data = vstack((
array([k,0,0]) + rand(s,3),
array([0,k,0]) + rand(s,3),
array([0,0,k]) + rand(s,3)
))
color = array([[1,0,0]]*s + [[0,1,0]]*s + [[0,0,1]]*s)
newdata,ax = ternaryPlot(data)
ax.scatter(
newdata[:,0],
newdata[:,1],
s=2,
alpha=0.5,
color=color
)
show()
我中的R撰写的包装具有的只是被接受CRAN,网页是 www.ggtern .COM :
它是基于关闭的 GGPLOT2 下,我已经作为一个平台。我的驱动力,是在我工作的一致性的愿望,并且,因为我大量使用GGPLOT2,包装的发展是一个合乎逻辑的发展。
对于那些你们谁使用GGPLOT2,使用ggtern的应该是轻而易举的事,而且,这里是一对夫妇可以达到什么样的示威。
<强>用下面的代码制作人:强>
# Load data
data(Feldspar)
# Sort it by decreasing pressure
# (so small grobs sit on top of large grobs
Feldspar <- Feldspar[with(Feldspar, order(-P.Gpa)), ]
# Build and Render the Plot
ggtern(data = Feldspar, aes(x = An, y = Ab, z = Or)) +
#the layer
geom_point(aes(fill = T.C,
size = P.Gpa,
shape = Feldspar)) +
#scales
scale_shape_manual(values = c(21, 24)) +
scale_size_continuous(range = c(2.5, 7.5)) +
scale_fill_gradient(low = "green", high = "red") +
#theme tweaks
theme_tern_bw() +
theme(legend.position = c(0, 1),
legend.justification = c(0, 1),
legend.box.just = "left") +
#tweak guides
guides(shape= guide_legend(order =1,
override.aes=list(size=5)),
size = guide_legend(order =2),
fill = guide_colourbar(order=3)) +
#labels and title
labs(size = "Pressure/GPa",
fill = "Temperature/C") +
ggtitle("Feldspar - Elkins and Grove 1990")
等高线图也已修补的三元环境,并且,一个新的几何形状的夹杂物用于经由表示置信区间的马氏距离
<强>用下面的代码制作人:强>
ggtern(data=Feldspar,aes(An,Ab,Or)) +
geom_confidence(aes(group=Feldspar,
fill=..level..,
alpha=1-..level..),
n=2000,
breaks=c(0.01,0.02,0.03,0.04,
seq(0.05,0.95,by=0.1),
0.99,0.995,0.9995),
color=NA,linetype=1) +
geom_density2d(aes(color=..level..)) +
geom_point(fill="white",aes(shape=Feldspar),size=5) +
theme_tern_bw() +
theme_tern_nogrid() +
theme(ternary.options=element_ternary(padding=0.2),
legend.position=c(0,1),
legend.justification=c(0,1),
legend.box.just="left") +
labs(color="Density",fill="Confidence",
title="Feldspar - Elkins and Grove 1990 + Confidence Levels + Density") +
scale_color_gradient(low="gray",high="magenta") +
scale_fill_gradient2(low="red",mid="orange",high="green",
midpoint=0.8) +
scale_shape_manual(values=c(21,24)) +
guides(shape= guide_legend(order =1,
override.aes=list(size=5)),
size = guide_legend(order =2),
fill = guide_colourbar(order=3),
color= guide_colourbar(order=4),
alpha= "none")
Veusz 支持三元曲线图。下面是从href="http://home.gna.org/veusz/examples/#ternary" rel="nofollow noreferrer">文档的
小克路易斯开发三角情节通用类,意在支持土壤质地三角形 使用Python和Matplotlib。这是可以在这里<击> http://nature.berkeley.edu/~chlewis/Sourcecode.html 击> HTTPS ://github.com/chlewissoil/TernaryPlotPy
克洛伊编辑补充:它移动到更可靠的主机!此外,这是一个公开回购,所以如果你想要求库化,你可以添加一个问题。希望这是有用的人。
我刚发现其中使用Python / Matplotlib以生成三元曲线称为wxTernary的工具。它通过 http://wxternary.sourceforge.net/ 是可用的 - 我是能够成功地生成三元相图在第一次尝试。
有似乎是在工作中实现这里一>在gnuplot的: 结果 <子>(来源: ugm.ac.id 一>)子>
查找矢量绘图库,并从头开始绘制,如果你不能找到一个更简单的方法来做到这一点。
有一个名为A R包 soiltexture 。它的目的是在土壤质地三角的情节,但可以定制一些方面。