लीजेंड में केवल टेक्स्ट दिखाने के लिए legend() में handlelength=0, handletextpad=0, fancybox=False सेट करें।
चरण
- फिगर साइज़ और ऑटोलेआउट सेट करें।
- रैंडम डेटा प्लॉट करें और लेबल दें।
ax.legend(loc="upper right", handlelength=0, handletextpad=0, fancybox=True)से लीजेंड बनाएं।plt.show()से दिखाएं।
उदाहरण कोड
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.random.rand(100)
y = np.random.rand(100)
fig, ax = plt.subplots()
ax.plot(x, y, label='Zig-Zag', c="red")
ax.legend(loc="upper right", handlelength=0, handletextpad=0, fancybox=True)
plt.show()
आउटपुट
लीजेंड बॉक्स में केवल "Zig-Zag" टेक्स्ट, कोई लाइन/मार्कर सिंबल नहीं।