anydyce.viz
package reference
Experimental
This package is an attempt to explore conveniences for integration with Matplotlib. It is an explicit departure from RFC 1925, ยง 2.2 and should be considered experimental. Be warned that future release may introduce incompatibilities or remove this package altogether. Feedback, suggestions, and contributions are welcome and appreciated.
HLikeT = Union[H, HableT]
module-attribute
ImageType
Bases: str
, Enum
Source code in anydyce/viz.py
70 71 72 |
|
PNG = 'PNG'
class-attribute
instance-attribute
SVG = 'SVG'
class-attribute
instance-attribute
TraditionalPlotType
Bases: str
, Enum
Source code in anydyce/viz.py
75 76 77 78 |
|
AT_LEAST = 'At Least'
class-attribute
instance-attribute
AT_MOST = 'At Most'
class-attribute
instance-attribute
NORMAL = 'Normal'
class-attribute
instance-attribute
HPlotter
Experimental
This class should be considered experimental and may change or disappear in future versions.
A plotter responsible for laying out control widgets and visualizing data provided by primary and optional secondary histograms. (See the plot method.)
Source code in anydyce/viz.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
|
NAME() -> str
The display name of the plotter.
Source code in anydyce/viz.py
646 647 648 649 650 651 |
|
layout(plot_widgets: PlotWidgets) -> widgets.Widget
Takes a set of widgets (plot_widgets) and returns a container (layout) widget selecting those needed by the plotter.
Source code in anydyce/viz.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
|
plot(hs: Sequence[tuple[str, H, Optional[H]]], settings: SettingsDict)
abstractmethod
Creates and displays a visualization of the provided histograms. fig is the
matplotlib.figure.Figure
in which the visualization should be constructed. hs is a sequence of
three-tuples, a name, a primary histogram, and an optional secondary histogram
(None
if omitted). Plotters should implement this function to
display at least the primary histogram and visually associate it with the name.
Source code in anydyce/viz.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
|
transparent(requested: bool) -> bool
Returns whether this plotter produces plots which support transparency if
requested. The default implementation always returns False
.
Source code in anydyce/viz.py
685 686 687 688 689 690 691 |
|
BarHPlotter
Bases: HPlotter
Experimental
This class should be considered experimental and may change or disappear in future versions.
A plotter for creating a single vertical bar plot visualizing all primary histograms. Secondary histograms are ignored.
Source code in anydyce/viz.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
|
NAME = 'Bar Plot'
class-attribute
instance-attribute
layout(plot_widgets: PlotWidgets) -> widgets.Widget
Source code in anydyce/viz.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
|
plot(hs: Sequence[tuple[str, H, Optional[H]]], settings: SettingsDict) -> None
Source code in anydyce/viz.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
|
BurstHPlotter
Bases: HPlotter
Experimental
This class should be considered experimental and may change or disappear in future versions.
A plotter for creating one burst plot per primary histogram. If provided, associated secondary histograms are used for the outer rings.
Source code in anydyce/viz.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
|
NAME = 'Burst Plots'
class-attribute
instance-attribute
layout(plot_widgets: PlotWidgets) -> widgets.Widget
Source code in anydyce/viz.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
|
plot(hs: Sequence[tuple[str, H, Optional[H]]], settings: SettingsDict) -> None
Source code in anydyce/viz.py
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
|
transparent(requested: bool) -> bool
Source code in anydyce/viz.py
881 882 883 |
|
HorizontalBarHPlotter
Bases: BarHPlotter
Experimental
This class should be considered experimental and may change or disappear in future versions.
A plotter for creating one horizontal bar plot per primary histogram. Secondary histograms are ignored.
Source code in anydyce/viz.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 |
|
NAME = 'Horizontal Bar Plots'
class-attribute
instance-attribute
plot(hs: Sequence[tuple[str, H, Optional[H]]], settings: SettingsDict) -> None
Source code in anydyce/viz.py
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 |
|
LineHPlotter
Bases: HPlotter
Experimental
This class should be considered experimental and may change or disappear in future versions.
A plotter for creating a single line plot visualizing all primary histograms. Secondary histograms are ignored.
Source code in anydyce/viz.py
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
|
NAME = 'Line Plot'
class-attribute
instance-attribute
layout(plot_widgets: PlotWidgets) -> widgets.Widget
Source code in anydyce/viz.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 |
|
plot(hs: Sequence[tuple[str, H, Optional[H]]], settings: SettingsDict) -> None
Source code in anydyce/viz.py
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
|
ScatterHPlotter
Bases: LineHPlotter
Experimental
This class should be considered experimental and may change or disappear in future versions.
A plotter for creating a single scatter plot visualizing all primary histograms. Secondary histograms are ignored.
Source code in anydyce/viz.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
|
NAME = 'Scatter Plot'
class-attribute
instance-attribute
plot(hs: Sequence[tuple[str, H, Optional[H]]], settings: SettingsDict) -> None
Source code in anydyce/viz.py
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
|
PlotWidgets
Bases: _PlotWidgetsDataclass
Experimental
This class should be considered experimental and may change or disappear in future versions.
Class to encapsulate interactive plot control widgets. All parameters for the initializer are optional.
-
initial_alpha is the starting alpha value for graphs (defaults to
0.75
). -
initial_burst_cmap_inner is the initially selected color map for inner burst graphs (defaults to
"RdYlGn_r"
). -
initial_burst_cmap_link is the starting value for linking the color maps for inner and outer burst graphs (defaults to
True
). -
initial_burst_cmap_outer is the initially selected color map for outer burst graphs (defaults to
"RdYlBu_r"
). -
initial_burst_color_bg is the initially selected background color for burst graphs (defaults to
"white"
). -
initial_burst_color_bg_trnsp is the initially selected background transparency color burst graphs (defaults to
False
). -
initial_burst_color_text is the initially selected text color for burst graphs (defaults to
"black"
). -
initial_burst_columns is the initially selected number of columns for displaying burst graphs (defaults to
3
). -
initial_burst_swap is whether the inner and outer burst graphs should be swapped at first (defaults to
False
). -
initial_burst_zero_fill_normalize is whether all burst graphs should share a scale at first (i.e., so similar values share similar colors across burst graphs) (defaults to
False
). -
initial_enable_cutoff is whether small values should be omitted from graphs at first (defaults to
True
). -
initial_graph_type is the type of graph first shown (defaults to
TraditionalPlotType.NORMAL
). -
initial_img_type is the initially selected image type (defaults to
ImageType.PNG
). -
initial_markers are the starting set of markers for line and scatter plots (defaults to
"oX^v><dP"
). -
initial_plot_style is the starting color style for non-burst graphs (defaults to
"bmh"
). -
initial_show_shadow is whether shadows should be shown for non-burst graphs at first (defaults to
False
). -
initial_resolution is the starting value for the graph resolution (defaults to
12
).
Source code in anydyce/viz.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
__init__(*, initial_alpha: float = DEFAULT_ALPHA, initial_burst_cmap_inner: str = DEFAULT_CMAP_BURST_INNER, initial_burst_cmap_link: bool = True, initial_burst_cmap_outer: str = DEFAULT_CMAP_BURST_OUTER, initial_burst_color_bg: str = DEFAULT_COLOR_BG, initial_burst_color_bg_trnsp: bool = False, initial_burst_color_text: str = DEFAULT_COLOR_TEXT, initial_burst_columns: int = DEFAULT_COLS_BURST, initial_burst_swap: bool = False, initial_burst_zero_fill_normalize: bool = False, initial_enable_cutoff: bool = True, initial_graph_type: TraditionalPlotType = TraditionalPlotType.NORMAL, initial_img_type: ImageType = ImageType.PNG, initial_markers: str = DEFAULT_MARKERS, initial_plot_style: str = DEFAULT_PLOT_STYLE, initial_resolution: int = DEFAULT_RESOLUTION, initial_show_shadow: bool = False)
Source code in anydyce/viz.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
asdict() -> dict[str, Any]
Source code in anydyce/viz.py
629 630 631 |
|
cumulative_probability_formatter(outcome: RealLike, probability: Fraction, h: H) -> str
Experimental
This function should be considered experimental and may change or disappear in future versions.
Formatter for use with plot_burst
to inefficiently
(i.e., \(O \left( {n} ^ {2} \right)\)) calculate and format cumulative probability
pairs for outcome in h.
Source code in anydyce/viz.py
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
|
outcome_name_formatter(outcome: RealLike, _, __) -> str
Experimental
This function should be considered experimental and may change or disappear in future versions.
Formatter for use with plot_burst
to format each
outcome. If outcome has a name attribute (e.g., as with an Enum
),
that is used. Otherwise outcome is passed to str
and the result is
used.
Source code in anydyce/viz.py
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 |
|
outcome_name_probability_formatter(outcome: RealLike, probability: Fraction, __) -> str
Experimental
This function should be considered experimental and may change or disappear in future versions.
Formatter for use with plot_burst
to display each
outcome and probability (separated by a newline). If outcome has a name
attribute (e.g., as with an Enum
), that is used. Otherwise outcome is
passed to str
and the result is used. probability is passed to
float
and formatted to two decimal places.
Source code in anydyce/viz.py
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 |
|
limit_for_display(h: H, cutoff) -> H
Experimental
This function should be considered experimental and may change or disappear in future versions.
Discards outcomes in h, starting with the smallest counts as long as the total
discarded in proportion to h.total
does not exceed cutoff. This can
be useful in speeding up plots where there are large number of negligible
probabilities.
1 2 3 4 5 6 7 8 9 10 |
|
Source code in anydyce/viz.py
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 |
|
probability_formatter(_, probability: Fraction, __) -> str
Experimental
This function should be considered experimental and may change or disappear in future versions.
Formatter for use with plot_burst
to display the
probability for each outcome (but not the outcome itself). probability is passed
to float
and formatted to two decimal places.
Source code in anydyce/viz.py
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 |
|
values_xy_for_graph_type(h: H, graph_type: TraditionalPlotType) -> tuple[tuple[RealLike, ...], tuple[float, ...]]
Source code in anydyce/viz.py
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
|
plot_bar(ax: Axes, hs: Sequence[tuple[str, H]], graph_type: TraditionalPlotType = TraditionalPlotType.NORMAL, alpha: float = DEFAULT_ALPHA, shadow: bool = False) -> None
Experimental
This function should be considered experimental and may change or disappear in future versions.
Plots a bar graph of hs using
ax with alpha
and shadow. hs is a sequence of two-tuples (pairs) of strings (labels) and H
objects. Bars are interleaved and non-overlapping, so this is best suited to plots
where hs contains a small number of histograms.
Source code in anydyce/viz.py
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 |
|
plot_line(ax: Axes, hs: Sequence[tuple[str, H]], graph_type: TraditionalPlotType = TraditionalPlotType.NORMAL, alpha: float = DEFAULT_ALPHA, shadow: bool = False, markers: str = 'o') -> None
Experimental
This function should be considered experimental and may change or disappear in future versions.
Plots a line graph of hs using
ax with alpha
and shadow. hs is a sequence of two-tuples (pairs) of strings (labels) and
dyce.H
objects. markers is cycled through when creating each line.
For example, if markers is "o+"
, the first histogram in hs will be
plotted with a circle, the second will be plotted with a plus, the third will be
plotted with a circle, the fourth will be plotted with a plus, and so on.
Source code in anydyce/viz.py
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 |
|
plot_scatter(ax: Axes, hs: Sequence[tuple[str, H]], graph_type: TraditionalPlotType = TraditionalPlotType.NORMAL, alpha: float = DEFAULT_ALPHA, shadow: bool = False, markers: str = '<>v^dPXo') -> None
Experimental
This function should be considered experimental and may change or disappear in future versions.
Plots a scatter graph of hs using
ax with alpha
and shadow. hs is a sequence of two-tuples (pairs) of strings (labels) and
dyce.H
objects. markers is cycled through when creating each line. For
example, if markers is "o+"
, the first histogram in hs will be
plotted with a circle, the second will be plotted with a plus, the third will be
plotted with a circle, the fourth will be plotted with a plus, and so on.
Source code in anydyce/viz.py
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
|
plot_burst(ax: Axes, h_inner: H, h_outer: Optional[H] = None, title: Optional[str] = None, inner_formatter: HFormatterT = outcome_name_formatter, inner_cmap: Union[str, matplotlib.colors.Colormap] = DEFAULT_CMAP_BURST_INNER, outer_formatter: Optional[HFormatterT] = None, outer_cmap: Union[str, matplotlib.colors.Colormap, None] = None, text_color: str = DEFAULT_COLOR_TEXT, alpha: float = DEFAULT_ALPHA) -> None
Experimental
This function should be considered experimental and may change or disappear in future versions.
Creates a dual, overlapping, cocentric pie chart in ax, which can be useful for visualizing relative probability distributions. Examples can be found in Additional interfaces.
Source code in anydyce/viz.py
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 |
|
plot_burst_subplot(h_inner: H, h_outer: Optional[H] = None, title: Optional[str] = None, inner_formatter: HFormatterT = outcome_name_formatter, inner_cmap: Union[str, matplotlib.colors.Colormap] = DEFAULT_CMAP_BURST_INNER, outer_formatter: Optional[HFormatterT] = None, outer_cmap: Union[str, matplotlib.colors.Colormap, None] = None, text_color: str = DEFAULT_COLOR_TEXT, alpha: float = DEFAULT_ALPHA) -> tuple[Figure, Axes]
Experimental
This function should be considered experimental and may change or disappear in future versions.
Wrapper around plot_burst
that creates a figure, axis
pair, calls
matplotlib.pyplot.tight_layout
,
and returns the pair.
Source code in anydyce/viz.py
1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 |
|