7

私はquivermatplotlibでベクトルを描画するために使用しています:

from itertools import chain
import matplotlib.pyplot as pyplot
pyplot.figure()
pyplot.axis('equal')
axis = pyplot.gca()
axis.quiver(*zip(*map(lambda l: chain(*l), [
    ((0, 0), (3, 1)),
    ((0, 0), (1, 0)),
])), angles='xy', scale_units='xy', scale=1)

axis.set_xlim([-4, 4])
axis.set_ylim([-4, 4])
pyplot.draw()
pyplot.show()

素敵な矢印が表示されますが、線のスタイルを点線や破線などに変更するにはどうすればよいですか?

4

1 に答える 1

11

ああ!実際にlinestyle='dashed'は動作します。矢筒の矢印はデフォルトでのみ塗りつぶされ、線幅が設定されていないだけです。それらはパスではなくパッチです。

次のようなことをすると:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.axis('equal')

ax.quiver((0,0), (0,0), (3,1), (1,0), angles='xy', scale_units='xy', scale=1,
          linestyle='dashed', facecolor='none', linewidth=1)

ax.axis([-4, 4, -4, 4])
plt.show()

ここに画像の説明を入力

破線の矢印が表示されますが、おそらく意図したものとはまったく異なります。

いくつかのパラメーターをいじって少し近づけることはできますが、それでも見た目は正確ではありません。

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.axis('equal')

ax.quiver((0,0), (0,0), (3,1), (1,0), angles='xy', scale_units='xy', scale=1,
          linestyle='dashed', facecolor='none', linewidth=2,
          width=0.0001, headwidth=300, headlength=500)

ax.axis([-4, 4, -4, 4])
plt.show()

ここに画像の説明を入力

したがって、別の回避策は、ハッチを使用することです。

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.axis('equal')

ax.quiver((0,0), (0,0), (3,1), (1,0), angles='xy', scale_units='xy', scale=1,
        hatch='ooo', facecolor='none')

ax.axis([-4, 4, -4, 4])
plt.show()

ここに画像の説明を入力

于 2013-03-12T03:42:40.750 に答える