mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar#
- 类 mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar(transform, size, label, loc, pad=0.1, borderpad=0.1, sep=2, frameon=True, size_vertical=0, color='black', label_top=False, fontproperties=None, fill_bar=None, **kwargs)[source]#
-
在下方绘制一个水平比例尺,并带有一个居中对齐的标签。
- 参数:
- transform
Transform
所用坐标系的变换对象,即
matplotlib.axes.Axes.transData
。- size浮点数
尺寸条的水平长度,以 transform 指定的坐标系单位给出。
- labelstr
要显示的标签。
- locstr
尺寸条的位置。有效位置包括“upper left”(左上)、“upper center”(中上)、“upper right”(右上)、“center left”(中左)、“center”(居中)、“center right”(中右)、“lower left”(左下)、“lower center”(中下)、“lower right”(右下)。为向下兼容,也接受数字值。详见
Legend
的参数 loc。- pad浮点数,默认值:0.1
标签和尺寸条周围的填充,以字体大小的比例表示。
- borderpad浮点数,默认值:0.1
边框填充,以字体大小的比例表示。
- sep浮点数,默认值:2
标签和尺寸条之间的间距,以点为单位。
- frameonbool,默认值:True
如果为 True,则在水平条和标签周围绘制一个框。
- size_vertical浮点数,默认值:0
尺寸条的垂直长度,以 transform 指定的坐标系单位给出。
- color字符串,默认值:'black'
尺寸条和标签的颜色。
- label_top布尔值,默认值:False
如果为 True,标签将位于尺寸条上方。
- fontproperties
FontProperties
,可选 标签文本的字体属性。
- fill_bar布尔值,可选
如果为 True 且 size_vertical 非零,则尺寸条将填充尺寸条指定的颜色。如果 *size_vertical* 大于零,则默认为 True,否则为 False。
- **kwargs
转发给
AnchoredOffsetbox
的关键字参数。
- transform
- 属性:
- size_bar
AuxTransformBox
尺寸条的容器。
- txt_label
TextArea
尺寸条标签的容器。
- size_bar
备注
如果 *prop* 作为关键字参数传递,而 *fontproperties* 未传递,则 *prop* 被视为预期的 *fontproperties*。不支持同时使用 *prop* 和 *fontproperties*。
示例
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> from mpl_toolkits.axes_grid1.anchored_artists import ( ... AnchoredSizeBar) >>> fig, ax = plt.subplots() >>> ax.imshow(np.random.random((10, 10))) >>> bar = AnchoredSizeBar(ax.transData, 3, '3 data units', 4) >>> ax.add_artist(bar) >>> fig.show()
使用所有可选参数
>>> import matplotlib.font_manager as fm >>> fontprops = fm.FontProperties(size=14, family='monospace') >>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, ... sep=5, borderpad=0.5, frameon=False, ... size_vertical=0.5, color='white', ... fontproperties=fontprops)
- set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, bbox_to_anchor=<UNSET>, child=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)[source]#
一次性设置多个属性。
支持的属性包括:
属性
描述
一个过滤函数,它接受一个 (m, n, 3) 浮点数组和一个 dpi 值,并返回一个 (m, n, 3) 数组以及图像左下角的两个偏移量
浮点数或 None
布尔值
未知
未知
BboxBase
或 None布尔值
Patch 或 (Path, Transform) 或 None
str
浮点数
布尔值
object
布尔值
(float, float) 或 callable
列表,元素类型为
AbstractPathEffect
None 或 布尔值 或 浮点数 或 可调用对象
布尔值
(scale: 浮点数, length: 浮点数, randomness: 浮点数)
布尔值或 None
str
布尔值
浮点数
浮点数