如何将mpl_toolkits的“ AnchoredSizeBar”放置在其给定的轴外

时间:2019-05-29 21:10:58

标签: python-3.x matplotlib

在将AnchoredSizeBar放置在给定轴之外时,我面临严重的困难。从AnchoredSizeBar参考中,loc属性仅接受相对于用于AnchoredSizeBar创建的给定轴的“字符串”方法。

因此,如果我想在给定轴之外设置AnchoredSizeBar位置,则loc属性将不起作用。实际上,这会引发错误消息。

有人知道解决该问题的方法吗?

如果可能的话,我想创建一个AnchoredSizeBar,其条形尺寸仍然相对于图中的给定轴,但是AnchoredSizeBar的位置可以放置在图形实例内的任何位置。

以下是我想要的代码片段:

import matplotlib.pyplot as plt


from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar


fig, ax = plt.subplots(figsize=(3, 3))

x_position = 0.15
y_position = 0.35

Figure_location = (x_position, y_position)    # figure xy locations relative to fig.transFigure.

axes_width_to_size_bar = 0.3

bar0 = AnchoredSizeBar(ax.transData, axes_width_to_size_bar, 'unfilled', loc=Figure_location, frameon=False, size_vertical=0.05, fill_bar=False)

ax.add_artist(bar0)


bar0_extent = bar0.get_extent()

fig.show()

谢谢您的宝贵时间。真诚的,

Philipe Riskalla Leal

1 个答案:

答案 0 :(得分:1)

android { defaultConfig { ... multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.3' } 的子类AnchoredSizeBar。因此,其他参数将传递给matplotlib.offsetbox.AnchoredOffsetbox。这提供了参数AnchoredOffsetboxbbox_to_anchor。这些与图例中的相同,因此有关说明,请参见任何图例示例,例如How to put the legend out of the plot

例如,将AnchoredSizeBar放置在图的右上角,

bbox_transform

enter image description here