मैटप्लोटलिब में तीर कैसे बनाएं
Matplotlib में तीर खींचने के लिए, आप matplotlib.pyplot.row फ़ंक्शन का उपयोग कर सकते हैं , जो निम्नलिखित सिंटैक्स का उपयोग करता है:
matplotlib.pyplot.error(x, y, dx, dy)
सोना:
- x, y: तीर के आधार के x और y निर्देशांक
- dx, dy: x और y दिशाओं में तीर की लंबाई
यह ट्यूटोरियल इस फ़ंक्शन के व्यावहारिक उपयोग के कई उदाहरण प्रदान करता है।
उदाहरण 1: एक तीर खींचें
निम्नलिखित कोड दिखाता है कि Matplotlib प्लॉट पर एकल तीर कैसे बनाया जाए:
import matplotlib. pyplot as plt #define two arrays for plotting A = [3, 5, 5, 6, 7, 8] B = [12, 14, 17, 20, 22, 27] #create scatterplot, specifying marker size to be 40 plt. scatter (A, B, s= 40 ) #add arrow to plot plt. arrow (x= 4 , y= 18 , dx= 2 , dy= 5 , width= .08 ) #displayplot plt. show ()
ध्यान दें कि हम ऊर्ध्वाधर तीर बनाने के लिए dx=0 और क्षैतिज तीर बनाने के लिए dy=0 सेट कर सकते हैं।
उदाहरण के लिए, यहां लंबवत तीर बनाने का तरीका बताया गया है:
import matplotlib. pyplot as plt #define two arrays for plotting A = [3, 5, 5, 6, 7, 8] B = [12, 14, 17, 20, 22, 27] #create scatterplot, specifying marker size to be 40 plt. scatter (A, B, s= 40 ) #add arrow to plot plt. arrow (x= 4 , y= 18 , dx= 0 , dy= 5 , width= .08 ) #displayplot plt. show ()
उदाहरण 2: एक तीर को स्टाइल करना
डिफ़ॉल्ट रूप से, मैटप्लोटलिब में एक तीर काले किनारों के साथ नीला होता है लेकिन हम फेसकलर और एजकलर तर्कों का उपयोग करके इसे आसानी से बदल सकते हैं:
import matplotlib. pyplot as plt #define two arrays for plotting A = [3, 5, 5, 6, 7, 8] B = [12, 14, 17, 20, 22, 27] #create scatterplot, specifying marker size to be 40 plt. scatter (A, B, s= 40 ) #add arrow to plot plt. arrow (x= 4 , y= 18 , dx= 0 , dy= 5 , width= .08 , facecolor= 'red' , edgecolor= 'none' ) #displayplot plt. show ()
आप शैली गुणों की पूरी सूची यहां पा सकते हैं जिन्हें तीरों पर लागू किया जा सकता है।
उदाहरण 3: तीरों में एनोटेशन जोड़ें
निम्नलिखित कोड दिखाता है कि Matplotlib प्लॉट पर एक तीर के नीचे एक एनोटेशन कैसे जोड़ा जाए:
import matplotlib. pyplot as plt #define two arrays for plotting A = [3, 5, 5, 6, 7, 8] B = [12, 14, 17, 20, 22, 27] #create scatterplot, specifying marker size to be 40 plt. scatter (A, B, s= 40 ) #add arrow to plot plt. arrow (x= 4 , y= 18 , dx= 0 , dy= 5 , width= .08 ) #add annotation plt. annotate (' General direction ', xy = (3.4, 17)) #displayplot plt. show ()
अतिरिक्त संसाधन
मैटप्लोटलिब में वृत्त कैसे प्लॉट करें (उदाहरण के साथ)
मैटप्लोटलिब में आयत कैसे बनाएं (उदाहरण के साथ)