TernaryAxesSubplotPoisson
- class poisson_approval.TernaryAxesSubplotPoisson(scale=None, size_inches='auto', **kwargs)[source]
Subclass of
TernaryAxesSubplot
, defined in the package python-ternary.This class implements some additional methods for Poisson Approval. For some examples, cf. the corresponding tutorial.
- annotate_condorcet(right_order, top_order, left_order, d_order_fixed_share=None)[source]
Annotate who is the Condorcet winner depending on the region.
We consider a simplex where:
Fixed shares of voters have preference orders given by d_order_fixed_share.
The remaining voters are split between right_order, top_order and left_order in proportions that are given by the point in the simplex.
This method annotates the regions according to which candidate is the Condorcet winner, and indicates where no one is the Condorcet winner.
If there are weak orders and/or fixed shares of voters, the method may not work on all distributions because it relies on an external package called shapely. If there are rankings only and no fixed shares of voters, it is supposed to work on all distributions.
- Parameters
right_order (str) – The order whose share is maximal at the right corner.
top_order (str) – The order whose share is maximal at the top corner.
left_order (str) – The order whose share is maximal at the left corner.
d_order_fixed_share (dict, optional) – Key: order. Value: a fixed share of voters in [0, 1].
- annotate_simplex(text, position, horizontalalignment='center', verticalalignment='center', **kwargs)[source]
Adaptation of
annotate
.The input position is in the simplex (instead of the scaled simplex), i.e. coordinates are in [0, 1].
The default horizontal and vertical alignments are centered.
Notes
For the parameters, cf.
annotate
in python-ternary.
- f_point_values_(right, top, left)[source]
Data of a candidate heatmap.
This function can be used only after a candidate heatmap has been drawn. When given a point of the simplex, it considers the closest point where f was computed and returns the corresponding value. It does not recompute f, and in particular the result may not be the same as a direct application of f to the point given as input.
- Parameters
right (Number) –
top (Number) –
left (Number) –
- Returns
List of size 3. The value associated respectively to each candidate a, b, c.
- Return type
list
- gridlines_simplex(multiple=None, horizontal_kwargs=None, left_kwargs=None, right_kwargs=None, **kwargs)[source]
Adaptation of
gridlines
.The argument multiple is a grid step in [0, 1] (instead of [0, scale]).
Notes
For the parameters, cf.
gridlines
in python-ternary.
- heatmap_candidates(func, right_label, top_label, left_label, legend_title='', legend_style='palette', style='hexagonal', colorbar=False, file_save_data=None, **kwargs)[source]
Heatmap of a function from the simplex to 3D vectors.
- Parameters
func (callable) – The function to plot. Input: coordinates right, top, left in the simplex, i.e. that sum to 1. Output: a list of 3 numbers between 0 and 1.
right_label (str) – Label of the right corner.
top_label (str) – Label of the top corner.
left_label (str) – Label of the left corner.
legend_title (str) – Title of the legend.
legend_style (str) – The style of the legend. The two available options are
'palette'
and'color_patches'
. Cf.legend_palette()
andlegend_color_patches()
.style – Contrarily to default settings in python-ternary, the default is
'hexagonal'
.colorbar – Contrarily to default settings in python-ternary, the default is False.
file_save_data (str) – File where the computed data will be saved (using
pickle
).kwargs – All other keywords arguments are passed to method
heatmap
of python-ternary.
Examples
>>> def g(right, top, left): ... a = top**.5 ... b = left**2. ... c = 1 - a - b ... return [a, b, c] >>> figure, tax = ternary_figure(scale=5) >>> tax.heatmap_candidates(g, ... left_label='left', ... right_label='right', ... top_label='top', ... legend_title='Candidates', ... legend_style='palette') >>> tax.set_title_padded('A candidate heat map')
To retrieve the computed value that is closest to a given point:
>>> tax.f_point_values_(right=0.5, top=0.3, left=0.2) [0.4472135954999579, 0.04000000000000001, 0.5127864045000421]
- heatmap_intensity(func, right_label, top_label, left_label, style='hexagonal', cmap='plasma', **kwargs)[source]
Adaptation of
heatmapf
.- Parameters
func (callable) – The function to plot. Input: coordinates right, top, left in the simplex, i.e. that sum to 1. Output: a number.
right_label (str) – Label of the right corner.
top_label (str) – Label of the top corner.
left_label (str) – Label of the left corner.
style (str) – Contrarily to default settings in python-ternary, the default is
'hexagonal'
.cmap (str) – Colormap. Contrarily to default settings in python-ternary, the default is
'plasma'
.kwargs – All other keywords arguments are passed to method
heatmapf
of python-ternary.
Examples
>>> def f(right, top, left): ... return (right**2 + top) / (left + 1) >>> figure, tax = ternary_figure(scale=10) >>> tax.heatmap_intensity(f, ... left_label='left', ... right_label='right', ... top_label='top') >>> tax.set_title_padded('An intensity heat map')
- horizontal_line_simplex(i, color='black', **kwargs)[source]
Adaptation of
horizontal_line
.The argument i is in [0, 1] (instead of [0, scale]).
Notes
For the parameters, cf.
horizontal_line
in python-ternary.
- left_parallel_line_simplex(i, color='black', **kwargs)[source]
Adaptation of
left_parallel_line
.The argument i is in [0, 1] (instead of [0, scale]).
Notes
For the parameters, cf.
left_parallel_line
in python-ternary.
- legend_color_patches(title, all_mixes=False, data=None)[source]
Add a “color patches” legend to the current figure (for candidates heat maps).
- Parameters
title (str) – Title of the legend.
all_mixes (bool) – If True, then all mixes are indicated in the legend: a + b, a + c, b + c and a + b + c.
data (dict, optional) – Key : anything. Value: a tuple, list, etc giving an RGB or RGBA code. This is used only if all_mixes is False.
Notes
The color patches for single candidates a, b, c are in the legend anyway.
If all_mixes is True, then all mixes are indicated in the legend.
If all_mixes is False and data is given, then if at least a value is close to a perfect mix (like half of a and half of b), then this mix is added to the legend.
- static legend_palette(title)[source]
Add a “palette” legend to the current figure (for candidates heat maps).
- Parameters
title (str) – Title of the legend.
Notes
This is more a hack than a real matplotlib legend. Hence the usual commands to choose the position of the legend, for example, are not meant to work here.
- line_simplex(p1, p2, color='black', **kwargs)[source]
Adaptation of
line
.The input positions are in the simplex (instead of the scaled simplex), i.e. coordinates are in [0, 1].
Notes
For the parameters, cf.
line
in python-ternary.