Matplotlib में कई पॉइंट्स के लिए एनोटेटेड टेक्स्ट जोड़ने के लिए, हम निम्नलिखित चरण ले सकते हैं:
- फिगर साइज सेट करें और सबप्लॉट्स के बीच और आसपास पैडिंग एडजस्ट करें।
- Numpy का उपयोग करके x और y डेटा पॉइंट्स बनाएं।
- प्रत्येक स्कैटर्ड पॉइंट के लिए लेबल सेट करने के लिए, लेबल्स की एक लिस्ट बनाएं।
- scatter() मेथड का उपयोग करके xpoints, ypoints प्लॉट करें। कलर के लिए, xpoints का उपयोग करें।
- ज़िप्ड लेबल्स, xpoints और ypoints पर इटरेट करें।
- फॉर लूप में बोल्ड लेटेक्स प्रतिनिधित्व के साथ annotate() मेथड का उपयोग करें।
- फिगर प्रदर्शित करने के लिए, show() मेथड का उपयोग करें।
उदाहरण
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 10, 10) ypoints = np.random.rand(10) labels = ["%.2f" % i for i in xpoints] plt.scatter(xpoints, ypoints, c=xpoints) for label, x, y in zip(labels, xpoints, ypoints): plt.annotate( f"$\\bf{label}$", xy=(x, y), xytext=(-20, 20), textcoords='offset points', ha='center', va='bottom', arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0')) plt.show()आउटपुट

