2013-03-12 6 views
6

मैं quiver उपयोग कर रहा हूँ matplotlib में वैक्टर आकर्षित करने के लिए:मैटलप्लिब के साथ 2 डी वैक्टर प्लॉटिंग?

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() 

जो मुझे अच्छा तीर देता है, लेकिन मैं कैसे बदल सकते हैं उनके लाइन शैली बिंदीदार के लिए, धराशायी, आदि?

+1

'linestyle = 'dashed' 'काम करना चाहिए, [दस्तावेज़ीकरण के अनुसार] (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.quiver)। स्पष्ट रूप से यह काम नहीं कर रहा है, हालांकि। यह शायद एक बग है। –

+0

@ जोकिंगटन: :(वर्कअराउंड के लिए कोई सुझाव? – Mehrdad

+0

दुर्भाग्यवश मेरे सिर के ऊपर से नहीं, दुर्भाग्य से ... –

उत्तर

10

आह! असल में, 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() 

enter image description here

आप धराशायी हो तीर, लेकिन शायद काफी नहीं है कि तुम क्या मन में था।

आप थोड़ा और करीब पाने के लिए कुछ पैरामीटर में चारों ओर खेल सकते हैं, लेकिन यह अभी भी वास्तव में अच्छा नहीं लगता है:

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() 

enter image description here

इसलिए, एक और वैकल्पिक हल hatches उपयोग करने के लिए किया जाएगा :

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() 

enter image description here

+0

+1 धन्यवाद, अभी भी आदर्श हाहा के बावजूद कुछ भी बेहतर नहीं है। – Mehrdad

+0

दूसरी समस्या: यदि हम किसी भिन्न पहलू पर ज़ूम करते हैं अनुपात, तीर का विकृत विकृत हो जाता है। –

संबंधित मुद्दे