Python quiver plot without head

99封情书 提交于 2021-01-27 12:54:36

问题


I'd like to make a quiver plot without the heads of the arrows. I also want to have borders so that the arrows could stand out of the background color plot. Here is the main part of my code trying to produce such a plot:

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)

The plot is in polar axis if this matters. This works for most of the lines except for those that are very short. Some artificial tails from the border are produced after the lines in those cases. One of the plots I generated that suffers the most from this is the following:

Any solutions to this problem or suggestions to bypass it will be greatly appreciated! Thanks!


回答1:


Specifying the headaxislength parameter for the arrows to be zero does the trick:

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)

The code above results in the following quiverplots, without arrowheads.



来源:https://stackoverflow.com/questions/37154071/python-quiver-plot-without-head

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!