- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用带有插图缩放功能的 matplotlib 绘制绘图。我发现以下示例将生成带有插图的图:
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()
但是,我无法找到正确的参数来传递 mark_inset()
函数,以便使拳击线的线宽变粗,或者颜色线变红。
通过搜索文档,我找不到参数 fc
和 ec
分别代表什么。
最佳答案
在 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')
要更改插入线,请对红色进行如下更改:
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", lw=2, ec='r')
为您提供以下类型的输出:
Matplot 库为 mark_inset 定义了 fc
和 ec
:
facecolor
或 fc
- mpl 颜色规范,或默认无,或“无”因为没有颜色。 edgecolor
或 ec
- mpl 颜色规范,或无默认值,或“无”表示无颜色。关于python - Matplotlib,控制 mark_inset() 属性(kwargs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35838111/
假设我想将绘图插入到图形中,但插入图的轴范围与我标记插入的轴范围不同。例如: fig, ax = plt.subplots() axins = inset_axes(ax, 1,1 , loc=2,
这个解释起来有点棘手。基本上,我想制作一个插图,然后利用 mpl_toolkits.axes_grid1.inset_locator.mark_inset 的便利性,但我希望插图中的数据完全独立于父轴
我想在一个子图中绘制阻尼随机游走的时间序列,然后在第二个子图中放大它。我知道来自 matplotlib 的 mark_inset,它工作正常。到目前为止我的代码是: from mpl_toolkits
我有这个代码 ax = plt.subplot(222) plt.plot(time_list, data[1], color='red') plt.plot(time_list, y_offset,
我正在尝试使用带有插图缩放功能的 matplotlib 绘制绘图。我发现以下示例将生成带有插图的图: import matplotlib.pyplot as plt from mpl_toolkits
在带有插图轴的图中,我想使用 mpl_toolkits.axes_grid1.inset_locator.mark_inset 标记插图。但是,我在控制 zorder 和标记插入的结果线的剪裁时遇到了
我是一名优秀的程序员,十分优秀!