前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >除了超赞三元相图,还有二元相和圆形图例?!这个可视工具有点猛~~

除了超赞三元相图,还有二元相和圆形图例?!这个可视工具有点猛~~

作者头像
DataCharm
发布2022-10-25 10:28:26
7470
发布2022-10-25 10:28:26
举报
文章被收录于专栏:数据 学术 商业 新闻

之前的推文中,小编给出了Python和R关于三元相图的绘制方法(我汇总了所有三元相图(ternary plots)的绘制方法,超实用!!),最近在查找资料的同时,小编还发现了其他类型的三元图,如三元相多边形图,即使用多边形(Polygon) 展示不同类别数据在三元相坐标体系中的组成,而完成这一操作的可视化库为Python-poisson_approval库,这个库除了绘制三元相图外,还可以绘制二元相图(Binary Plots),此外,还存在许多其他有用的函数和计算方法,更多内容可查看:poisson_approval库官网[1]

本期推文主要介绍其可视化部分~~

poisson_approval库绘制三元相多边形图

poisson_approval库绘制的三元相图主要表现组成占比情况,主要依赖python-ternary库,这里主要介绍其绘制的三元相图类型,如下:

  • Number of Equilibria
代码语言:javascript
复制
import matplotlib.pyplot as plt
import poisson_approval as pa
from fractions import Fraction

SCALE = 21
simplex_to_profile = pa.SimplexToProfile(
    pa.ProfileNoisyDiscrete,
    right_type='c>a~b',
    top_type=('abc', 0.5, 0.01),
    left_type=('bac', 0.5, 0.01),
    d_type_fixed_share={('abc', 0.1, 0.01): Fraction(1, 10),
                        ('abc', 0.9, 0.01): Fraction(1, 10)}
)
pa.ternary_plot_n_equilibria(
    simplex_to_profile,
    scale=SCALE,
    title='Number of ordinal equilibria')

Number of Equilibria Example01

还可以通过调整meth参数进行图表样式更改:

代码语言:javascript
复制
pa.ternary_plot_n_equilibria(
    simplex_to_profile,
    scale=SCALE,
    title='Number of group equilibria',
    meth='analyzed_strategies_group')

Number of Equilibria Example02

  • Winners at Equilibrium 这类图表使用了不同填充颜色去表示组成,如下:
代码语言:javascript
复制
pa.ternary_plot_winners_at_equilibrium(
    simplex_to_profile,
    scale=SCALE,
    title='Winners in ordinal equilibria')

Winners at Equilibrium Example02

  • Winning Frequencies in Fictitious Play or Iterated Voting

使用一种三元图例表示组成占比:

代码语言:javascript
复制
pa.ternary_plot_winning_frequencies(simplex_to_profile, scale=SCALE, n_max_episodes=100)

Example01

通过修改meth、perception_update_ratio等参数进行绘制调整:

代码语言:javascript
复制
pa.ternary_plot_winning_frequencies(
    simplex_to_profile,
    scale=SCALE,
    meth='iterated_voting',
    init='random_tau_undominated',
    samples_per_point=10,
    perception_update_ratio=1,
    ballot_update_ratio=1,
    winning_frequency_update_ratio=pa.one_over_t,
    n_max_episodes=100,
    title='Winning frequencies in iterated voting',
    legend_title='Winners'
)

Example02

以上就是poisson_approval库绘制三元相图的部分案例,可以看出,无论从组成占比和图例设置等都是新的一种三元相图系列。更多样例及设置参数可参考:tutorial_ernary_plots[2]

poisson_approval库绘制二元相图

poisson_approval库绘制二元相图 的基本原理和三元相图的绘制相同,这里介绍基本的案例,如下:

  • Number of Equilibria
代码语言:javascript
复制
pa.binary_plot_n_equilibria(
    xyy_to_profile,
    xscale=XSCALE, yscale=YSCALE,
    title='Number of ordinal equilibria')

Number of Equilibria

  • Winners at Equilibrium
代码语言:javascript
复制
pa.binary_plot_winners_at_equilibrium(
    xyy_to_profile,
    xscale=XSCALE, yscale=YSCALE,
    title='Winners in ordinal equilibria')

Winners at Equilibrium

  • Winning Frequencies in Fictitious Play or Iterated Voting
代码语言:javascript
复制
pa.binary_plot_winning_frequencies(
    xyy_to_profile,
    xscale=XSCALE, yscale=YSCALE,
    n_max_episodes=100)

Example

  • Advanced Intensity Heat Maps
代码语言:javascript
复制
def f(x, y1, y2):
    return (x**2 + y1) / (y2 + 1)
figure, tax = pa.binary_figure(xscale=XSCALE, yscale=YSCALE)
tax.heatmap_intensity(f,
                      x_left_label='x-left',
                      x_right_label='x-right',
                      y_left_label='y-left',
                      y_right_label='y-right')
tax.set_title('An intensity heat map')

Advanced Intensity Heat Maps

  • Advanced Candidate Heat Maps
代码语言:javascript
复制
def g(x, y1, y2):
    a = x**.5
    b = y1**2
    c = 1 - a - b
    return [a, b, c]
figure, tax = pa.binary_figure(xscale=XSCALE, yscale=YSCALE)
tax.heatmap_candidates(g,
                       x_left_label='x-left',
                       x_right_label='x-right',
                       y_left_label='y-left',
                       y_right_label='y-right',
                       legend_title='Candidates',
                       legend_style='palette')
tax.set_title('A candidate heat map')

Advanced Candidate Heat Maps

更多样例及设置参数可参考:tutorial_binary_plots[3]

总结

今天的这篇推文小编主要介绍另一种样式的三元相图(Ternary Plots) ,同时还介绍二元相图(Binary Plots) 的绘制,可能该类图表在实际使用中的限制条件较多,但小伙伴们可以当作一种新的图表思维进行学习哈~~

参考资料

[1]

poisson_approval库官网: https://francois-durand.github.io/poisson_approval/index.html。

[2]

tutorial_ernary_plots: https://poisson-approval.readthedocs.io/en/latest/tutorials/tutorial_ternary_plots.html。

[3]

tutorial_binary_plots: https://poisson-approval.readthedocs.io/en/latest/tutorials/tutorial_binary_plots.html。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-09-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DataCharm 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • poisson_approval库绘制三元相多边形图
  • poisson_approval库绘制二元相图
  • 总结
    • 参考资料
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档