如何使用 Julia 的 PyPlot.jl 向图形添加补丁

How to add patches to a figure using Julia's PyPlot.jl

示例:

using PyPlot
fig = gcf(); ax0=subplot(2,2,2)
ax1 = subplot(2,2,4)
ax0tr = ax0[:transAxes]; ax1tr = ax1[:transAxes] 
figtr = fig[:transFigure]
# 2. Transform arroww start point from axis 0 to figure coordinates
ptB = figtr[:transform](ax0tr[:transform]((20., -0.5)))
# 3. Transform arroww end point from axis 1 to figure coordinates
ptE = figtr[:transform](ax1tr[:transform]((20., 1.)))
# 4. Create the patch
arroww = matplotlib[:patches][:FancyArrowPatch](
ptB, ptE, transform=figtr,  # Place arroww in figure coord system
fc = "C0", alpha = 0.25, connectionstyle="arc3,rad=0.2",
arrowstyle="simple",
mutation_scale = 40.0)
# 5. Add patch to list of objects to draw onto the figure
push!(fig[:patches], arroww)
fig[:show]()

如何将面片对象添加到图形并在图形上实际看到它?这是行不通的。它不会抛出任何错误,但我看不到任何箭头。

(我也不能使用函数 arrow 因为我想创建一个从子图到子图的箭头)。

因为这仍然是热门搜索结果,这里有一个解决方案(使用 Julia 1.5.3)

import PyPlot; const plt = PyPlot
fig = plt.figure(figsize=(6,8), dpi=150)
ax0 = fig.add_subplot(2,2,2)
ax1 = fig.add_subplot(2,2,4)
arrow = patches.ConnectionPatch(
    [0.2,1],
    [0.6,0.5],
    coordsA=ax0.transData,
    coordsB=ax1.transData,
    color="black",
    arrowstyle="-|>",
    mutation_scale=30,
    linewidth=3,
)
fig.patches = [arrow]

它产生了以下情节。