【问题标题】:How to create mpltern ternary plot with matplot lib and pandas dataframe如何使用 matplotlib 和 pandas 数据框创建熔融三元图
【发布时间】:2022-11-01 18:44:30
【问题描述】:

我正在尝试使用 mpltern 库创建三元散点图。reference

import matplotlib.pyplot as plt
from mpltern.ternary.datasets import get_scatter_points


ax = plt.subplot(projection='ternary')

for seed in [1, 9, 6, 8]:
  ax.scatter(*get_scatter_points(11, seed=seed), alpha=0.5, label=seed)

ax.legend()

plt.show()

坚持如何在熊猫数据框中为“分析类型-微生物污染”、“分析类型-其他污染”、“分析类型-组成”列执行相同操作

根据库的 get_scatter_points 函数

def get_scatter_points(n=201, seed=19680801):
  np.random.seed(seed)
  t = np.random.rand(n)
  l = np.random.rand(n)
  r = np.random.rand(n)
  s = (t + l + r)
  t /= s
  l /= s
  r /= s
  return t, l, r

【问题讨论】:

    标签: python pandas matplotlib visualization


    【解决方案1】:
    ax = fig.add_subplot(projection='ternary')
    
    for c in countries:
        t0 = df[df['Country '] == c][['AnalysisType-Microbiologicalcontamination']].values
        l0 = df[df['Country '] == c][['AnalysisType-Othercontamination']].values
        r0 = df[df['Country '] == c][['AnalysisType-Composition']].values
        ax.scatter(t0, l0, r0, alpha=0.5,label = c)
    ax.legend()
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2018-05-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 1970-01-01
      • 2020-11-19
      • 2018-11-07
      • 2020-09-22
      • 2020-05-06
      相关资源
      最近更新 更多