MCPcopy
hub / github.com/pydata/xarray / _add_legend

Function _add_legend

xarray/plot/utils.py:1714–1752  ·  view source on GitHub ↗
(
    hueplt_norm: _Normalize,
    sizeplt_norm: _Normalize,
    primitive,
    legend_ax,
    plotfunc: str,
)

Source from the content-addressed store, hash-verified

1712
1713
1714def _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
1755def _guess_coords_to_plot(

Callers 2

newplotfuncFunction · 0.90
add_legendMethod · 0.90

Calls 5

legend_elementsFunction · 0.85
_legend_add_subtitleFunction · 0.85
label_from_attrsFunction · 0.85
_adjust_legend_subtitlesFunction · 0.85
argsortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…