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

Function _adjust_legend_subtitles

xarray/plot/utils.py:1198–1224  ·  view source on GitHub ↗

Make invisible-handle "subtitles" entries look more like titles.

(legend)

Source from the content-addressed store, hash-verified

1196
1197
1198def _adjust_legend_subtitles(legend):
1199 """Make invisible-handle "subtitles" entries look more like titles."""
1200 import matplotlib.pyplot as plt
1201
1202 # Legend title not in rcParams until 3.0
1203 font_size = plt.rcParams.get("legend.title_fontsize", None)
1204 hpackers = legend.findobj(plt.matplotlib.offsetbox.VPacker)[0].get_children()
1205 hpackers = [v for v in hpackers if isinstance(v, plt.matplotlib.offsetbox.HPacker)]
1206 for hpack in hpackers:
1207 areas = hpack.get_children()
1208 if len(areas) < 2:
1209 continue
1210 draw_area, text_area = areas
1211
1212 handles = draw_area.get_children()
1213
1214 # Assume that all artists that are not visible are
1215 # subtitles:
1216 if not all(artist.get_visible() for artist in handles):
1217 # Remove the dummy marker which will bring the text
1218 # more to the center:
1219 draw_area.set_width(0)
1220 for text in text_area.get_children():
1221 if font_size is not None:
1222 # The sutbtitles should have the same font size
1223 # as normal legend titles:
1224 text.set_size(font_size)
1225
1226
1227def _infer_meta_data(ds, x, y, hue, hue_style, add_guide, funcname):

Callers 1

_add_legendFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…