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

标签 matplotlib julia patch

示例:

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]

它产生以下图。

Arrow from top subplot to bottom subplot

关于matplotlib - 如何使用 Julia 的 PyPlot.jl 向图形添加补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45213290/

相关文章:

python - matplotlib中条形图中的断轴斜线标记?

python - matplotlib 中的矢量格式热图

vector - 元组向量的逐元素比较 Julia

linux - 使用被子应用有序的补丁列表

git - 修复后如何应用被拒绝的帅哥?

python - 有没有办法使用 'matplotlib' 生成 Retina 图?

python - 类型错误 : histogram() got an unexpected keyword argument 'new'

julia introspection - 获取传递给函数的变量名称

dataframe - 如何在 DataFrames Julia 的特定列中不区分大小写地搜索包含特殊单词大小写的行?

java - 是否有可以为您的 java/scala 应用程序实现的自动更新程序/修补程序?