matplotlib.legend_handler#

默认的图例处理程序。

重要

这是一个低级别的图例API,大多数终端用户不需要它。

我们建议您在阅读此文档之前熟悉 图例指南

图例处理程序应为一个具有以下签名的可调用对象:

legend_handler(legend, orig_handle, fontsize, handlebox)

其中 legend 是图例本身,orig_handle 是原始图,fontsize 是以像素为单位的字体大小,handlebox 是一个 OffsetBox 实例。在调用中,您应该创建相关的艺术家(使用 legend 和/或 orig_handle 中的相关属性)并将它们添加到 handlebox 中。艺术家需要根据 fontsize 进行缩放(注意,大小是以像素为单位的,即这是一个 dpi 缩放的值)。

此模块包括从基类(HandlerBase)派生的几个图例处理类,具有以下方法:

def legend_artist(self, legend, orig_handle, fontsize, handlebox)
class matplotlib.legend_handler.HandlerBase(xpad=0.0, ypad=0.0, update_func=None)[源代码][源代码]#

默认图例处理程序的基类。

派生类旨在重写 create_artists 方法,该方法具有以下签名:

def create_artists(self, legend, orig_handle,
                   xdescent, ydescent, width, height, fontsize,
                   trans):

被重写的方法需要创建适合给定维度(xdescent, ydescent, width, height)的变换艺术家,如果需要的话,这些艺术家应按字体大小进行缩放。

参数:
xpad浮点数, 可选

在 x 方向上的填充。

ypad浮点数, 可选

在y方向上的填充。

update_func可调用对象,可选

用于从另一个图例处理程序更新图例处理程序属性的函数,由 update_prop 使用。

adjust_drawing_area(legend, orig_handle, xdescent, ydescent, width, height, fontsize)[源代码][源代码]#
create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

legend_artist(legend, orig_handle, fontsize, handlebox)[源代码][源代码]#

返回此 HandlerBase 为给定的原始艺术家/句柄生成的艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : matplotlib.artist.Artist 或类似对象matplotlib.artist.Artist 或类似

这些图例艺术家正在为其创建的对象。

字体大小int

字体大小以像素为单位。创建的艺术家应根据给定的字体大小进行缩放。

handleboxOffsetBox

用于存放此图例条目艺术家的创建框。在 legend_artist 方法中创建的艺术家必须在此方法内添加到此手柄框中。

update_prop(legend_handle, orig_handle, legend)[源代码][源代码]#
class matplotlib.legend_handler.HandlerCircleCollection(yoffsets=None, sizes=None, **kwargs)[源代码][源代码]#

用于 CircleCollection 的处理器。

参数:
numpointsint

在图例条目中显示的点数。

yoffsets浮点数数组

长度 numpoints 的列表,包含图例条目中每个点的y偏移量。

**kwargs

转发到 HandlerNpoints 的关键字参数。

create_collection(orig_handle, sizes, offsets, offset_transform)[源代码][源代码]#
class matplotlib.legend_handler.HandlerErrorbar(xerr_size=0.5, yerr_size=None, marker_pad=0.3, numpoints=None, **kwargs)[源代码][源代码]#

错误条的处理器。

参数:
marker_pad浮动

图例条目中各点之间的填充。

numpointsint

在图例条目中显示的点数。

**kwargs

转发到 HandlerBase 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

get_err_size(legend, xdescent, ydescent, width, height, fontsize)[源代码][源代码]#
class matplotlib.legend_handler.HandlerLine2D(marker_pad=0.3, numpoints=None, **kwargs)[源代码][源代码]#

处理 Line2D 实例的处理器。

参见

HandlerLine2DCompound

一个较早的处理程序实现,它使用一个艺术家来绘制线条,另一个艺术家来绘制标记。

参数:
marker_pad浮动

图例条目中各点之间的填充。

numpointsint

在图例条目中显示的点数。

**kwargs

转发到 HandlerBase 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

class matplotlib.legend_handler.HandlerLine2DCompound(marker_pad=0.3, numpoints=None, **kwargs)[源代码][源代码]#

用于 Line2D 实例的原始处理程序,依赖于将仅包含线条的图形与仅包含标记的图形组合。未来可能会被弃用。

参数:
marker_pad浮动

图例条目中各点之间的填充。

numpointsint

在图例条目中显示的点数。

**kwargs

转发到 HandlerBase 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

class matplotlib.legend_handler.HandlerLineCollection(marker_pad=0.3, numpoints=None, **kwargs)[源代码][源代码]#

处理 LineCollection 实例的处理器。

参数:
marker_pad浮动

图例条目中各点之间的填充。

numpointsint

在图例条目中显示的点数。

**kwargs

转发到 HandlerBase 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

get_numpoints(legend)[源代码][源代码]#
class matplotlib.legend_handler.HandlerNpoints(marker_pad=0.3, numpoints=None, **kwargs)[源代码][源代码]#

一个图例处理器,在图例条目中显示 numpoints 个点。

参数:
marker_pad浮动

图例条目中各点之间的填充。

numpointsint

在图例条目中显示的点数。

**kwargs

转发到 HandlerBase 的关键字参数。

get_numpoints(legend)[源代码][源代码]#
get_xdata(legend, xdescent, ydescent, width, height, fontsize)[源代码][源代码]#
class matplotlib.legend_handler.HandlerNpointsYoffsets(numpoints=None, yoffsets=None, **kwargs)[源代码][源代码]#

一个图例处理程序,显示图例中的 numpoints ,并允许它们在 y 方向上单独偏移。

参数:
numpointsint

在图例条目中显示的点数。

yoffsets浮点数数组

长度 numpoints 的列表,包含图例条目中每个点的y偏移量。

**kwargs

转发到 HandlerNpoints 的关键字参数。

get_ydata(legend, xdescent, ydescent, width, height, fontsize)[源代码][源代码]#
class matplotlib.legend_handler.HandlerPatch(patch_func=None, **kwargs)[源代码][源代码]#

处理 Patch 实例的处理器。

参数:
patch_func可调用对象,可选

创建图例键艺术家的函数。patch_func 应具有以下签名:

def patch_func(legend=legend, orig_handle=orig_handle,
               xdescent=xdescent, ydescent=ydescent,
               width=width, height=height, fontsize=fontsize)

随后,创建的艺术家将调用其 update_prop 方法,并应用适当的变换。

**kwargs

转发到 HandlerBase 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

class matplotlib.legend_handler.HandlerPathCollection(yoffsets=None, sizes=None, **kwargs)[源代码][源代码]#

用于 PathCollection 的处理器,这些处理器由 scatter 使用。

参数:
numpointsint

在图例条目中显示的点数。

yoffsets浮点数数组

长度 numpoints 的列表,包含图例条目中每个点的y偏移量。

**kwargs

转发到 HandlerNpoints 的关键字参数。

create_collection(orig_handle, sizes, offsets, offset_transform)[源代码][源代码]#
class matplotlib.legend_handler.HandlerPolyCollection(xpad=0.0, ypad=0.0, update_func=None)[源代码][源代码]#

用于 fill_betweenstackplot 中的 PolyCollection 的处理程序。

参数:
xpad浮点数, 可选

在 x 方向上的填充。

ypad浮点数, 可选

在y方向上的填充。

update_func可调用对象,可选

用于从另一个图例处理程序更新图例处理程序属性的函数,由 update_prop 使用。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

class matplotlib.legend_handler.HandlerRegularPolyCollection(yoffsets=None, sizes=None, **kwargs)[源代码][源代码]#

处理 RegularPolyCollection 的处理器。

参数:
numpointsint

在图例条目中显示的点数。

yoffsets浮点数数组

长度 numpoints 的列表,包含图例条目中每个点的y偏移量。

**kwargs

转发到 HandlerNpoints 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

create_collection(orig_handle, sizes, offsets, offset_transform)[源代码][源代码]#
get_numpoints(legend)[源代码][源代码]#
get_sizes(legend, orig_handle, xdescent, ydescent, width, height, fontsize)[源代码][源代码]#
update_prop(legend_handle, orig_handle, legend)[源代码][源代码]#
class matplotlib.legend_handler.HandlerStem(marker_pad=0.3, numpoints=None, bottom=None, yoffsets=None, **kwargs)[源代码][源代码]#

用于处理由 stem 生成的图的处理器。

参数:
marker_padfloat, 默认值: 0.3

图例条目中各点之间的填充。

numpointsint, 可选

在图例条目中显示的点数。

底部浮点数, 可选
yoffsets浮点数数组,可选

长度 numpoints 的列表,包含图例条目中每个点的y偏移量。

**kwargs

转发到 HandlerNpointsYoffsets 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

get_ydata(legend, xdescent, ydescent, width, height, fontsize)[源代码][源代码]#
class matplotlib.legend_handler.HandlerStepPatch(xpad=0.0, ypad=0.0, update_func=None)[源代码][源代码]#

处理 StepPatch 实例的处理器。

参数:
xpad浮点数, 可选

在 x 方向上的填充。

ypad浮点数, 可选

在y方向上的填充。

update_func可调用对象,可选

用于从另一个图例处理程序更新图例处理程序属性的函数,由 update_prop 使用。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

class matplotlib.legend_handler.HandlerTuple(ndivide=1, pad=None, **kwargs)[源代码][源代码]#

Tuple 的处理程序。

参数:
ndivideint 或 None, 默认值: 1

将图例区域划分的段数。如果为 None,则使用输入元组的长度。

pad : float, 默认值: rcParams["legend.borderpad"] (default: 0.4)浮点数,默认值:

以字体大小的分数为单位的填充。

**kwargs

转发到 HandlerBase 的关键字参数。

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[源代码][源代码]#

返回生成的图例艺术家。

参数:
图例 : Legend图例

这些图例艺术家正在为其创建的图例。

orig_handle : Artist 或类似对象艺术家或类似职业

这些图例艺术家正在为其创建的对象。

xdescent, ydescent, width, heightint

矩形 (xdescent, ydescent, width, height) 是创建图例艺术家时应适应的范围。

字体大小int

字体大小(以像素为单位)。创建的图例艺术家应根据给定的字体大小进行缩放。

trans转换

应用于正在创建的图例艺术家的变换。通常是从处理框中的单位坐标到屏幕坐标的变换。

matplotlib.legend_handler.update_from_first_child(tgt, src)[源代码][源代码]#