无头Python箭袋图

2024-09-28 03:22:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个没有箭头的箭袋图。我还想有边框,这样箭头就可以从背景色图中脱颖而出。下面是我试图生成这样一个图的代码的主要部分:

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)

如果这很重要的话,情节就在极轴上。除了那些很短的线之外,这对大多数线路都有效。在这种情况下,边界上的一些人造尾巴是在线条之后产生的。我生成的其中一个受此影响最大的图是:

Quiver plot with artifacts at the end of lines

任何解决这个问题的方法或建议绕过它将不胜感激!谢谢!在


Tags: 代码plt箭头widthcolor边框whitescale
1条回答
网友
1楼 · 发布于 2024-09-28 03:22:03

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)

上面的代码生成了下面的quiverblot,没有箭头。 quiverplot without arrows

相关问题 更多 >

    热门问题