我有一系列20个图(不是子图)可以在一个图中制作.我希望传说能够在盒子之外.同时,我不想改变轴,因为图形的大小减少了.请帮助我以下查询:
我希望能够在一组父轴上叠加多个插入轴,如下所示:
理想情况下,我希望每组插入轴的锚点固定在数据坐标中,但是轴的x,y范围要与图形尺寸而不是数据的比例一致.
例如,如果我放大父轴中的某个区域,我希望插入轴的位置与父轴中绘制的数据一起移动,但是它们的面积和纵横比保持不变.我正在寻找的确切行为类似于情节标记或matplotlib.Annotation
实例.但是,我决定只能在数据坐标中设置轴的范围.
我知道我可以传递rect
参数axes()
来指定标准化图形坐标中的位置和范围.但是,我需要将我的轴锚定到数据坐标中的特定点.
我也尝试过这样的事情:
from matplotlib import pyplot as pp
fig,parent_ax = pp.subplots(1,1)
parent_ax.set_xlim(0,1)
parent_ax.set_ylim(0,1)
# desired axis bounding box in data coordinates
rect = (0.1,0.2,0.2,0.3)
child_ax = axes(rect)
# apply transformation to data coordinates of parent axis
child_ax.set_transform(parent_ax.transData)
Run Code Online (Sandbox Code Playgroud)
它没有所需的效果(我的子轴的x,y限制现在耦合到父轴的x,y限制,我不想要,并且它的位置仍然不在数据坐标中).
我也看过这里的各种例子,但是它们似乎都没有完全符合我的要求,即允许我在数据坐标中指定一个任意的锚点.
有任何想法吗?
我想在第一个轴的右上角添加第二个轴。谷歌搜索后,我找到了两种方法来做这样的事情:fig.add_axes()
, 和mpl_toolkits.axes_grid.inset_locator.inset_axes
. 但fig.add_axes()
不接受transform
arg。所以下面的代码会抛出一个错误。所以位置不能在父轴坐标下,而是在图形坐标下。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
ax2 = fig.add_axes([0.8, 0, 0.2, 0.2], transform=ax.transAxes, projection=ccrs.PlateCarree())
Run Code Online (Sandbox Code Playgroud)
并且inset_axes()
不接受projection
arg,所以我不能添加ax2
为 cartopy geo-axes。
from mpl_toolkits.axes_grid.inset_locator import inset_axes
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
# The following line doesn't work
ax2 = inset_axes(ax, width='20%', height='20%', axes_kwargs={'projection': ccrs.PlateCarree()})
# Doesn't work neither:
ax2 …
Run Code Online (Sandbox Code Playgroud)