【问题标题】:Python quiver plot without head没有头部的 Python 箭袋图
【发布时间】:2023-04-06 11:31:01
【问题描述】:

我想制作一个没有箭头的箭袋图。我还希望有边框,以便箭头可以从背景颜色图中脱颖而出。这是我试图生成这样一个情节的代码的主要部分:

plt.quiver(phia[sl1,sl2], R0a[sl1,sl2],u,v, color='white', headlength=0, headwidth = 1, pivot = 'middle', scale = scale, width=width, linewidth = 0.5)

如果这很重要,情节就在极轴上。这适用于大多数行,除了那些非常短的行。在这些情况下,在线条之后会产生一些来自边界的人造尾巴。我生成的受此影响最大的图之一如下:

对此问题的任何解决方案或绕过它的建议将不胜感激!谢谢!

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    将箭头的 headaxislength 参数指定为零就可以了:

    import numpy as np
    import matplotlib.pyplot as plt
    
    theta = np.linspace(0, 2*np.pi, 16)
    r = np.linspace(0, 1, 6)
    x = np.cos(theta)[:,np.newaxis]*r
    y = np.sin(theta)[:,np.newaxis]*r
    
    quiveropts = dict(color='white', headlength=0, pivot='middle', scale=3, 
        linewidth=.5, units='xy', width=.05, headwidth=1) # common options
    f, (ax1, ax2) = plt.subplots(1,2, sharex=True, sharey=True)
    ax1.quiver(x,y, -y, x, headaxislength=4.5, **quiveropts) # the default
    ax2.quiver(x,y, -y, x, headaxislength=0, **quiveropts)
    

    上面的代码产生了以下不带箭头的箭形图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-04
      • 2017-02-22
      • 2017-03-17
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      相关资源
      最近更新 更多