Fxyang
Fxyang

Reputation: 293

Python quiver plot without head

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:

Quiver plot with artifacts at the end of lines

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

Upvotes: 3

Views: 8853

Answers (1)

Oliver W.
Oliver W.

Reputation: 13459

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. quiverplot without arrows

Upvotes: 5

Related Questions