इस प्रोग्राम में, हम matplot लाइब्रेरी का उपयोग करके दो रेखाएं प्लॉट करेंगे। कोडिंग शुरू करने से पहले, हमें निम्न कमांड का उपयोग करके matplotlib लाइब्रेरी आयोर्ट करने की आवश्यकता है -
Import matplotlib.pyplot as plt
Pyplot कमांड शैली फ़ंक्शन का एक संग्रह है जो matplotlib को MATLAB की तरह काम करता है।
एल्गोरिदम
चरण 1: matplotlib.pyplot आयात करें। चरण 2: line1 और line2 बिंदु परिभाषित करें। चरण 3: pyplot में plot() फ़ंक्शन का उपयोग करके रेखाएं प्लॉट करें। चरण 4: शीर्षक, X-अक्ष, Y-अक्ष परिभाषित करें। चरण 5: show() फ़ंक्शन का उपयोग करके प्लॉट प्रदर्शित करें।
उदाहरण कोड
import matplotlib.pyplot as plt
line1_x = [10, 20, 30]
line1_y = [20, 40, 10]
line2_x = [10, 20, 30]
line2_y = [40, 10, 30]
plt.xlabel('X AXIS')
plt.ylabel('Y AXIS')
plt.plot(line1_x, line1_y, color='blue', linewidth=3, label='line1-dotted', linestyle='dotted')
plt.plot(line2_x, line2_y, color='red', linewidth=5, label='line2-dashed', linestyle='dotted')
plt.title("PLOTTING DOTTED LINES")
plt.legend()
plt.show()
आउटपुट

व्याख्या
वेरिएबल line1_x, line_y और line2_x, line2_y हमारी रेखाओं के निर्देशांक हैं। plot फ़ंक्शन में linewidth पैरामीटर मूल रूप से हमारे द्वारा प्लॉट की जा रही रेखा की चौड़ाई/मोटाई है। प्रोग्राम में plt.legend() फ़ंक्शन का उपयोग ग्राफ पर x-अक्ष, y-अक्ष नाम जैसे लीजेंड रखने के लिए किया जाता है।