BinaryAxesSubplotPoisson

class poisson_approval.BinaryAxesSubplotPoisson(xscale=None, yscale=None, size_inches='auto')[source]

Wrapper for binary plots.

For some examples, cf. the tutorial on binary plots.

static annotate_condorcet(left_order, right_order, d_order_fixed_share=None)[source]

Annotate who is the Condorcet winner depending on the region.

We consider a setting where:

  • Fixed shares of voters have preference orders given by d_order_fixed_share.

  • The remaining voters are split between left_order and right_order in proportions that are given by the x coordinate.

This method annotates the regions according to which candidate is the Condorcet winner, and indicates where no one is the Condorcet winner.

Parameters
  • left_order (str) – The order whose share is maximal for x = 0.

  • right_order (str) – The order whose share is maximal for x = 1.

  • d_order_fixed_share (dict, optional) – Key: order. Value: a fixed share of voters in [0, 1].

heatmap_candidates(func, x_left_label, x_right_label, y_left_label, y_right_label, reverse_right=False, legend_title='', legend_style='palette', **kwargs)[source]

Heatmap of a function from a 3D vector (x, y1, y2) to a 3D vector.

Parameters
  • func (callable) – The function to plot. Input: coordinates x, y1, y2, each in [0, 1]. Output: a list of 3 numbers between 0 and 1.

  • x_left_label (str) – Label on the left of the x-axis.

  • x_right_label (str) – Label on the right of the x-axis.

  • y_left_label (str) – Label of the left y-axis.

  • y_right_label (str) – Label of the right y-axis.

  • reverse_right (bool) – If True, then the y-axis on the right goes decreasing from 1 to 0 (whereas the y-axis on the left goes increasing from 0 to 1).

  • 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() and legend_color_patches().

  • kwargs – All other keywords arguments are passed to method imshow of matplotlib.

Examples

>>> def g(x, y1, y2):
...     a = x**.5
...     b = y1**2
...     c = 1 - a - b
...     return [a, b, c]
>>> figure, tax = binary_figure(xscale=5, yscale=5)
>>> 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')
heatmap_intensity(func, x_left_label, x_right_label, y_left_label, y_right_label, reverse_right=False, cmap='plasma', **kwargs)[source]

Intensity heatmap.

Parameters
  • func (callable) – The function to plot. Input: coordinates x, y1, y2, each in [0, 1]. Output: a number.

  • x_left_label (str) – Label on the left of the x-axis.

  • x_right_label (str) – Label on the right of the x-axis.

  • y_left_label (str) – Label of the left y-axis.

  • y_right_label (str) – Label of the right y-axis.

  • reverse_right (bool) – If True, then the y-axis on the right goes decreasing from 1 to 0 (whereas the y-axis on the left goes increasing from 0 to 1).

  • cmap (str) – Colormap. Default: 'plasma'.

  • kwargs – All other keywords arguments are passed to method imshow of matplotlib.

Examples

>>> def f(x, y1, y2):
...     return (x**2 + y1) / (y2 + 1)
>>> figure, tax = binary_figure(xscale=5, yscale=5)
>>> 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')
static 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 (numpy.ndarray, optional) – Array m * n * 3. 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.

static set_title(title, **kwargs)[source]

Title of the plot.

Notes

For the parameters, cf. set_title in matplotlib.