(
hueplt_norm: _Normalize,
sizeplt_norm: _Normalize,
primitive,
legend_ax,
plotfunc: str,
)
| 1712 | |
| 1713 | |
| 1714 | def _add_legend( |
| 1715 | hueplt_norm: _Normalize, |
| 1716 | sizeplt_norm: _Normalize, |
| 1717 | primitive, |
| 1718 | legend_ax, |
| 1719 | plotfunc: str, |
| 1720 | ): |
| 1721 | primitive = primitive if isinstance(primitive, list) else [primitive] |
| 1722 | |
| 1723 | handles, labels = [], [] |
| 1724 | for huesizeplt, prop in [ |
| 1725 | (hueplt_norm, "colors"), |
| 1726 | (sizeplt_norm, "sizes"), |
| 1727 | ]: |
| 1728 | if huesizeplt.data is not None: |
| 1729 | # Get legend handles and labels that displays the |
| 1730 | # values correctly. Order might be different because |
| 1731 | # legend_elements uses np.unique instead of pd.unique, |
| 1732 | # FacetGrid.add_legend might have troubles with this: |
| 1733 | hdl, lbl = [], [] |
| 1734 | for p in primitive: |
| 1735 | hdl_, lbl_ = legend_elements(p, prop, num="auto", func=huesizeplt.func) |
| 1736 | hdl += hdl_ |
| 1737 | lbl += lbl_ |
| 1738 | |
| 1739 | # Only save unique values: |
| 1740 | u, ind = np.unique(lbl, return_index=True) |
| 1741 | ind = np.argsort(ind) |
| 1742 | lbl = cast(list, u[ind].tolist()) |
| 1743 | hdl = cast(list, np.array(hdl)[ind].tolist()) |
| 1744 | |
| 1745 | # Add a subtitle: |
| 1746 | hdl, lbl = _legend_add_subtitle(hdl, lbl, label_from_attrs(huesizeplt.data)) |
| 1747 | handles += hdl |
| 1748 | labels += lbl |
| 1749 | legend = legend_ax.legend(handles, labels, framealpha=0.5) |
| 1750 | _adjust_legend_subtitles(legend) |
| 1751 | |
| 1752 | return legend |
| 1753 | |
| 1754 | |
| 1755 | def _guess_coords_to_plot( |
no test coverage detected
searching dependent graphs…