嗯,我自己用了wikipedia article、SO post和一些蛮力解决了这个问题。对不起,代码墙,但你必须画出所有的绘图轮廓和标签等等。在import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import axes3d, Axes3D

from itertools import combinations

import pandas as pd

def plot_ax(): #plot tetrahedral outline

verts=[[0,0,0],

[1,0,0],

[0.5,np.sqrt(3)/2,0],

[0.5,0.28867513, 0.81649658]]

lines=combinations(verts,2)

for x in lines:

line=np.transpose(np.array(x))

ax.plot3D(line[0],line[1],line[2],c='0')

def label_points(): #create labels of each vertices of the simplex

a=(np.array([1,0,0,0])) # Barycentric coordinates of vertices (A or c1)

b=(np.array([0,1,0,0])) # Barycentric coordinates of vertices (B or c2)

c=(np.array([0,0,1,0])) # Barycentric coordinates of vertices (C or c3)

d=(np.array([0,0,0,1])) # Barycentric coordinates of vertices (D or c3)

labels=['a','b','c','d']

cartesian_points=get_cartesian_array_from_barycentric([a,b,c,d])

for point,label in zip(cartesian_points,labels):

if 'a' in label:

ax.text(point[0],point[1]-0.075,point[2], label, size=16)

elif 'b' in label:

ax.text(point[0]+0.02,point[1]-0.02,point[2], label, size=16)

else:

ax.text(point[0],point[1],point[2], label, size=16)

def get_cartesian_array_from_barycentric(b): #tranform from "barycentric" composition space to cartesian coordinates

verts=[[0,0,0],

[1,0,0],

[0.5,np.sqrt(3)/2,0],

[0.5,0.28867513, 0.81649658]]

#create transformation array vis https://en.wikipedia.org/wiki/Barycentric_coordinate_system

t = np.transpose(np.array(verts))

t_array=np.array([t.dot(x) for x in b]) #apply transform to all points

return t_array

def plot_3d_tern(df,c='1'): #use function "get_cartesian_array_from_barycentric" to plot the scatter points

#args are b=dataframe to plot and c=scatter point color

bary_arr=df.values

cartesian_points=get_cartesian_array_from_barycentric(bary_arr)

ax.scatter(cartesian_points[:,0],cartesian_points[:,1],cartesian_points[:,2],c=c)

#Create Dataset 1

np.random.seed(123)

c1=np.random.normal(8,2.5,20)

c2=np.random.normal(8,2.5,20)

c3=np.random.normal(8,2.5,20)

c4=[100-x for x in c1+c2+c3] #make sur ecomponents sum to 100

#df unecessary but that is the format of my real data

df1=pd.DataFrame(data=[c1,c2,c3,c4],index=['c1','c2','c3','c4']).T

df1=df1/100

#Create Dataset 2

np.random.seed(1234)

c1=np.random.normal(16,2.5,20)

c2=np.random.normal(16,2.5,20)

c3=np.random.normal(16,2.5,20)

c4=[100-x for x in c1+c2+c3]

df2=pd.DataFrame(data=[c1,c2,c3,c4],index=['c1','c2','c3','c4']).T

df2=df2/100

#Create Dataset 3

np.random.seed(12345)

c1=np.random.normal(25,2.5,20)

c2=np.random.normal(25,2.5,20)

c3=np.random.normal(25,2.5,20)

c4=[100-x for x in c1+c2+c3]

df3=pd.DataFrame(data=[c1,c2,c3,c4],index=['c1','c2','c3','c4']).T

df3=df3/100

fig = plt.figure()

ax = Axes3D(fig) #Create a 3D plot in most recent version of matplot

plot_ax() #call function to draw tetrahedral outline

label_points() #label the vertices

plot_3d_tern(df1,'b') #call function to plot df1

plot_3d_tern(df2,'r') #...plot df2

plot_3d_tern(df3,'g') #...

python金字塔图绘制_如何用R或Python绘制3d(4变量)三元(金字塔)图?相关推荐

  1. 箱式图 分组_小白学R(三):重复测量数据的箱式图上的p值如何改大小呢?

    上一期分享了重复数据箱式图的使用条件和数据格式小白学R(二):重复测量数据/连续数据的箱式图(ggplot包)(1),今天就奉上箱式图的代码和以及如何改箱式图上的p值大小. 画箱式图 1.1 先看数据 ...

  2. python中factor函数_左手用R右手Python系列——因子变量与分类重编码

    原标题:左手用R右手Python系列--因子变量与分类重编码 欢迎关注天善智能 hellobi.com,我们是专注于商业智能BI,大数据,数据分析领域的垂直社区,学习.问答.求职,一站式搞定! 对商业 ...

  3. anaconda下使用python怎样实现图像增强_如何用anaconda进行python开发

    展开全部 序 Python易用,但用好却不易,其中比较头疼的就是包管理和Python不同版本的问题,32313133353236313431303231363533e58685e5aeb9313333 ...

  4. 上海python招聘微信群_如何用20行Python代码打造一个微信群聊助手?

    今天要教大家一个黑科技,20行代码实现自己定制的微信群聊助手,可以用来活跃群气氛,好多群主创建完群后,拉完一群人,之后就一片寂静,有个群聊助手,就可以帮忙活跃群里气氛,通过今天在自己的微信上有一大批好 ...

  5. python新手入门教程思路-Python新手入门教程_教你怎么用Python做数据分析

    Python新手入门教程_教你怎么用Python做数据分析 跟大家讲了这么多期的Python教程,有小伙伴在学Python新手教程的时候说学Python比较复杂的地方就是资料太多了,比较复杂.很多网上 ...

  6. Matlab 李萨如图模拟_动态模拟李萨如图形形成过程保存为.GIF动图

       九层妖塔 起于垒土 Matlab 李萨如图模拟_动态模拟李萨如图形形成过程保存为.GIF动图 一.数学分析 二.程序设计及使用说明 三.动图 四.代码 一.数学分析 二.程序设计及使用说明 三. ...

  7. python等值面图平滑_离散点插值方法、等值线的绘制及平滑技巧

    离散点插值方法.等值线的绘制及平滑技巧 2008-06-10 22:45 由于等值线图看起来非常直观.形象 , 因此在天气预报.气候预测分析等方面用 得非常多 , 已成为预报员不可缺少的工具之一.如各 ...

  8. python 桑基图 地理坐标_手把手教你用Python绘制酷炫的桑基图

    最近 ,不止一次收到小伙伴的截图追问: "这个图叫什么 ? ? ?" "这个图真好看 ! ! !怎么画啊 ?" ...... 笔者本没有干货 ,问的人多了 ,也 ...

  9. python正则表达式中的r与转义字符_左手用R右手Python系列13——字符串处理与正则表达式...

    原标题:左手用R右手Python系列13--字符串处理与正则表达式 杜雨,EasyCharts团队成员,R语言中文社区专栏作者,兴趣方向为:Excel商务图表,R语言数据可视化,地理信息数据可视化.个 ...

最新文章

  1. 字节一面:如何从 100 亿 URL 中找出相同的 URL?
  2. Android RecycleView ScrollBy不生效
  3. makefile中的@ $ :
  4. selenium自动化测试_Selenium测试可实现有效的测试自动化
  5. spring学习(15):required属性
  6. Spring Boot基础讲解
  7. what is web farm
  8. 群赛 ZOJ3741(dp) ZOJ3911(线段树)
  9. T-Sql - 数据分租求最大指定字段最大的记录
  10. windows mysql memcached,Windows上的Memcached(不是memcache)PHP扩展
  11. mysql创建图书馆书库表格,mysql图书馆管理系统的数据库
  12. C语言!鸡兔同笼的程序
  13. 尚学堂马士兵hibernate讲义
  14. 智能选择:单位转换(unit conversion)
  15. Java代理模式及其应用
  16. Flutter升级空安全版本注意事项
  17. 硬件MSB最高位优先、LSB最低位优先的CRC计算原理详细解释和程序,正算反算成功等效,DS18B20和HTU31D传感器CRC
  18. Power Apps配置安全角色和对象权限
  19. ##if语句与if语句的嵌套
  20. 如何选择适合你的兴趣爱好(四十),美食

热门文章

  1. Python学习笔记:入门(2)
  2. 基于VTK的Qt应用程序开发
  3. Java基础----对象与类
  4. Evaluation of Deep Learning Toolkits
  5. 科大星云诗社动态20210813
  6. 【研讨课】超临界水气化制氢技术 2018-06-11
  7. 台湾大学林轩田机器学习技法课程学习笔记12 -- Neural Network
  8. 嵌入式编程与c语言有何区别,有的嵌入式设备也提供C++编译器,那还有理由坚持使用C语言吗?...
  9. hex editor怎么搜索代码_代码审计从入门到放弃(三) phplimit
  10. linux_unix编程手册-信号概述signal函数