Paul Goyes
Paul Goyes

Reputation: 59

How to use different linestyles in a quiver plot

How can I use two different linestyle in a quiver plot? I tried the same procedure as color, but it does not work. I send my code and the result.

import numpy as np
import matplotlib.pyplot as plt    
V = array([[-8.51111054e-01, -2.07125731e-02],
           [ 1.00514114e+00,  1.45925842e-02],
           [-9.20205414e-01, -8.90733267e-04],
           [-5.49162030e-01, -5.72392077e-04],
           [-3.20711851e-01,  1.04597686e-02],
           [ 7.85996497e-01,  1.78952999e-02]])

And now plot the vectors with origin at (0,0)

plt.figure()
plt.quiver([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], V.T[0,:], V.T[1,:], angles='xy', scale_units='xy',
           color=['b','b','r','r','k','k'],
           linestyle=('-','--','-','--','-','--'), scale=1)
plt.xlim(-1.5, 1.7)
plt.ylim(b.min()*1.2,b.max()*1.2)
plt.show()

Check the result: enter image description here

Upvotes: 1

Views: 2100

Answers (1)

Trenton McKinney
Trenton McKinney

Reputation: 62393

  • matplotlib.pyplot.quiver
  • This is a feature of the arrow outline, and is a misunderstanding of how linestyle works, which refers to the edges.
    • If linewidth is small, the edges aren't visible.
    • color is the facecolor, and obscures the edges. Use edgecolor or ec.
import matplotlib.pyplot as plt

plt.figure(figsize=(10, 10))
color=['b','b','r','r','k','k']
plt.quiver([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], V.T[0,:], V.T[1,:], angles='xy', scale_units='xy',
           ls=['solid','dashed','-.',':','-','--'], scale=1, linewidth=1, fc='none', ec=color)
plt.xlim(-1.5, 1.7)
plt.show()

enter image description here

  • Set ec to black and then use facecolor, but it's difficult to see.
plt.figure(figsize=(10, 10))
color=['g','g','r','r','orange','orange']
plt.quiver([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], V.T[0,:], V.T[1,:], angles='xy', scale_units='xy',
           color=color,
           ls=['solid','dashed','-.',':','-','--'], scale=1, linewidth=2, edgecolor='k')
plt.xlim(-1.5, 1.7)
plt.show()

enter image description here

Upvotes: 2

Related Questions