[英]Matplotlib, controlling mark_inset() properties (kwargs)
I am trying to make a plot with matplotlib with an inset zoom. 我正在尝试用matplotlib制作带有插入缩放的绘图。 I found the following example which will produce a plot with an inset:
我发现以下示例将生成带有插图的图:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
import numpy as np
def get_demo_image():
from matplotlib.cbook import get_sample_data
import numpy as np
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
z = np.load(f)
# z is a numpy array of 15x15
return z, (-3, 4, -4, 3)
fig, ax = plt.subplots(figsize=[5, 4])
# prepare the demo image
Z, extent = get_demo_image()
Z2 = np.zeros([150, 150], dtype="d")
ny, nx = Z.shape
Z2[30:30 + ny, 30:30 + nx] = Z
# extent = [-3, 4, -4, 3]
ax.imshow(Z2, extent=extent, interpolation="nearest",
origin="lower")
axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
axins.imshow(Z2, extent=extent, interpolation="nearest",
origin="lower")
# sub region of the original image
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
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=4, fc="none", ec="0.5")
plt.draw()
plt.show()
However, I am having trouble finding the correct arguments to pass the mark_inset()
function in order to make the linewidth of the boxing line thicker, or the color line red. 但是,我无法找到正确的参数来传递
mark_inset()
函数,以使拳击线的线宽更粗,或者颜色线为红色。
I could not find what the arguments fc
and ec
stand for either, by searching for the documentation. 通过搜索文档,我无法找到
fc
和ec
代表的参数。
Adding the following after the zoomed_inset_axes
should do what you need: 在
zoomed_inset_axes
之后添加以下zoomed_inset_axes
应该zoomed_inset_axes
您的需求:
axins = zoomed_inset_axes(ax, 6, loc=1)
for axis in ['top','bottom','left','right']:
axins.spines[axis].set_linewidth(3)
axins.spines[axis].set_color('r')
To change the inset lines change as follows for red: 要更改插入线,请按以下方式更改为红色:
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", lw=2, ec='r')
Giving you the following kind of output: 给你以下类型的输出:
The Matplot lib defines fc
and ec
as follows for mark_inset : Matplot lib为mark_inset定义了
fc
和ec
,如下所示:
facecolor
or fc
- mpl color spec, or None for default, or 'none' for no color. facecolor
或fc
- mpl color spec,默认为None,无颜色为'none'。 edgecolor
or ec
- mpl color spec, or None for default, or 'none' for no color. edgecolor
或ec
- mpl颜色规范,默认为None,无颜色为'none'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.