目前,我绘制的图形全部透明如下所示,这使得它可以区分缩放部分和原始部分。
另一件事是缩放部分的位置," loc"关键字只有1,... 9,9个选项,我可以使用坐标来指定我喜欢的位置吗?
axins = zoomed_inset_axes(ax, 3, loc=5) # zoom = 6
我写了一个简单的代码,你的修改目的。
from pylab import *
import re
rc('font',family='Arial')
matplotlib.rc('legend', fontsize=24)
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
font = {'family' : 'Arial',
'weight' : 'normal',
'size' : 24}
fig = figure(figsize=(8,8))
fig.set_alpha(0.0)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
x=[0,1]
y=[0,1]
plot(x,y)
axins = zoomed_inset_axes(ax, 3, loc=5) # zoom = 6
axins.plot(x,y)
# sub region of the original image
x1, x2, y1, y2 = 0.3, 0.4, 0.3,0.4
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
plt.xticks(visible=False)
plt.yticks(visible=False)
# draw a bbox of the region of the inset axes in the parent axes and
# connecting lines between the bbox and the inset axes area
mark_inset(ax, axins, loc1=2, loc2=3, fc="none", ec="0.5")
plt.draw()
plt.show()
fig.savefig('1.png', transparent=True)
答案 0 :(得分:1)
在致电savefig
之前,执行:
fig.patch.set_alpha(0)
ax.patch.set_alpha(0)
axins.patch.set_alpha(1)
axins.patch.set_facecolor('#909090')
这将使图形背景透明,也可以使主轴透明,但不会使缩放轴透明。
然后,请确保不要使用savefig
选项致电transparent=True
,因为这会删除所有背景。只需在该通话中设置transparent=False
,这也是savefig
的默认值。