之前的推文中,小编给出了Python和R关于三元相图的绘制方法(我汇总了所有三元相图(ternary plots)的绘制方法,超实用!!),最近在查找资料的同时,小编还发现了其他类型的三元图,如三元相多边形图,即使用多边形(Polygon) 展示不同类别数据在三元相坐标体系中的组成,而完成这一操作的可视化库为Python-poisson_approval库,这个库除了绘制三元相图外,还可以绘制二元相图(Binary Plots),此外,还存在许多其他有用的函数和计算方法,更多内容可查看:poisson_approval库官网[1]
本期推文主要介绍其可视化部分~~
poisson_approval库绘制的三元相图主要表现组成占比情况,主要依赖python-ternary库,这里主要介绍其绘制的三元相图类型,如下:
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参数进行图表样式更改:
pa.ternary_plot_n_equilibria(
simplex_to_profile,
scale=SCALE,
title='Number of group equilibria',
meth='analyzed_strategies_group')
Number of Equilibria Example02
pa.ternary_plot_winners_at_equilibrium(
simplex_to_profile,
scale=SCALE,
title='Winners in ordinal equilibria')
Winners at Equilibrium Example02
使用一种三元图例表示组成占比:
pa.ternary_plot_winning_frequencies(simplex_to_profile, scale=SCALE, n_max_episodes=100)
Example01
通过修改meth、perception_update_ratio等参数进行绘制调整:
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库绘制二元相图 的基本原理和三元相图的绘制相同,这里介绍基本的案例,如下:
pa.binary_plot_n_equilibria(
xyy_to_profile,
xscale=XSCALE, yscale=YSCALE,
title='Number of ordinal equilibria')
Number of Equilibria
pa.binary_plot_winners_at_equilibrium(
xyy_to_profile,
xscale=XSCALE, yscale=YSCALE,
title='Winners in ordinal equilibria')
Winners at Equilibrium
pa.binary_plot_winning_frequencies(
xyy_to_profile,
xscale=XSCALE, yscale=YSCALE,
n_max_episodes=100)
Example
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
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。