You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Julia的PyPlot中绘制半侧箭头头部(上侧或下侧)

在Julia的PyPlot中绘制半箭头头部(上侧/下侧)

你可以通过覆盖箭头头部的不需要部分来实现半箭头效果,这种方法基于你现有的完整箭头代码,无需复杂的样式自定义,直观易操作。

实现上侧半箭头

在绘制完整箭头后,用白色矩形覆盖箭头头部的下半部分:

using PyPlot
figure()
# 绘制箭杆和完整箭头
plot([0,0.8],[0,0.4],"k")
annotate("", xy=(0.8, 0.4),
    xytext=(0, 0),xycoords="data",
    arrowprops=Dict("edgecolor"=>"k", "facecolor"=>"k",
        "width"=>1, "linestyle"=>"-",
        "headlength"=>10,
        "headwidth"=>5),
    annotation_clip=false)
# 用白色矩形覆盖下半箭头头部,只保留上侧
arrow_head_x, arrow_head_y = 0.8, 0.4
# 矩形参数:(左下角x, 左下角y), 宽度, 高度;宽度对应headlength,高度对应headwidth的一半
gca().add_patch(matplotlib.patches.Rectangle(
    (arrow_head_x - 0.1, arrow_head_y - 0.025), 
    0.1, 0.025, 
    color="white", 
    zorder=2  # 确保矩形在箭头上方
))
axis("square")

实现下侧半箭头

同理,用白色矩形覆盖箭头头部的上半部分:

using PyPlot
figure()
# 绘制箭杆和完整箭头
plot([0,0.8],[0,0.4],"k")
annotate("", xy=(0.8, 0.4),
    xytext=(0, 0),xycoords="data",
    arrowprops=Dict("edgecolor"=>"k", "facecolor"=>"k",
        "width"=>1, "linestyle"=>"-",
        "headlength"=>10,
        "headwidth"=>5),
    annotation_clip=false)
# 用白色矩形覆盖上半箭头头部,只保留下侧
arrow_head_x, arrow_head_y = 0.8, 0.4
gca().add_patch(matplotlib.patches.Rectangle(
    (arrow_head_x - 0.1, arrow_head_y), 
    0.1, 0.025, 
    color="white", 
    zorder=2
))
axis("square")

参数说明

  • zorder=2:确保覆盖用的矩形在箭头上方,完全遮挡不需要的部分;
  • 矩形的宽度对应箭头的headlength(示例中为10,对应坐标单位的0.1),高度对应headwidth的一半(示例中为5,对应坐标单位的0.025),你可以根据自己的箭头大小调整这些数值。

内容的提问来源于stack exchange,提问作者christiankral

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 22:04:52