MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / HandlerLine2D

Class HandlerLine2D

lib/matplotlib/legend_handler.py:275–311  ·  view source on GitHub ↗

Handler for `.Line2D` instances. See Also -------- HandlerLine2DCompound : An earlier handler implementation, which used one artist for the line and another for the marker(s).

Source from the content-addressed store, hash-verified

273
274
275class HandlerLine2D(HandlerNpoints):
276 """
277 Handler for `.Line2D` instances.
278
279 See Also
280 --------
281 HandlerLine2DCompound : An earlier handler implementation, which used one
282 artist for the line and another for the marker(s).
283 """
284
285 def create_artists(self, legend, orig_handle,
286 xdescent, ydescent, width, height, fontsize,
287 trans):
288 # docstring inherited
289 xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent,
290 width, height, fontsize)
291
292 markevery = None
293 if self.get_numpoints(legend) == 1:
294 # Special case: one wants a single marker in the center
295 # and a line that extends on both sides. One will use a
296 # 3 points line, but only mark the #1 (i.e. middle) point.
297 xdata = np.linspace(xdata[0], xdata[-1], 3)
298 markevery = [1]
299
300 ydata = np.full_like(xdata, (height - ydescent) / 2)
301 legline = Line2D(xdata, ydata, markevery=markevery)
302
303 self.update_prop(legline, orig_handle, legend)
304
305 if legend.markerscale != 1:
306 newsz = legline.get_markersize() * legend.markerscale
307 legline.set_markersize(newsz)
308
309 legline.set_transform(trans)
310
311 return [legline]
312
313
314class HandlerPatch(HandlerBase):

Callers 1

legend_guide.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…