अंतिम फिगर का कलर प्राप्त करने के लिए, हम हर प्लॉट के लिए get_color() मेथड का उपयोग कर सकते हैं।
- फिगर का आकार सेट करें और सबप्लॉट्स के बीच और आसपास पैडिंग एडजस्ट करें।
- NumPy का उपयोग करके x और y डेटा पॉइंट बनाएं।
- plot() मेथड का उपयोग करके (x, x), (x, x2) और (x, x3) प्लॉट करें।
- हर प्लॉट लाइन के लिए लीजेंड रखें।
- get_color() मेथड का उपयोग करके प्रत्येक प्लॉट का कलर प्राप्त करें।
- फिगर प्रदर्शित करने के लिए, show() मेथड का उपयोग करें।
उदाहरण
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.arange(10)
y = np.arange(10)
p = plt.plot(x, y, x, y ** 2, x, y ** 3)
plt.legend([p[0], p[1], p[2]], ["$y=x$", "$y=x^2$", "$y=x^3$"])
print("Color of the first plot: ", p[0].get_color())
print("Color of the second plot: ", p[1].get_color())
print("Color of the third plot: ", p[2].get_color())
plt.show()आउटपुट

प्लॉट्स के साथ, आपको कंसोल पर निम्नलिखित आउटपुट प्रिंट होगा -
Color of the first plot: #1f77b4 Color of the second plot: #ff7f0e Color of the third plot: #2ca02c