बार के ऊपर इमोजी लेबल लगाने के लिए plt.annotate() का उपयोग करें।
चरण
- फिगर साइज़ और ऑटोलेआउट सेट करें।
- फ्रीक्वेंसीज़ और इमोजी लेबल्स की लिस्ट बनाएं।
plt.bar()से बार्स प्लॉट करें।- प्रत्येक बार के लिए
plt.annotate()से इमोजी ऊपर रखें (ha='center', va='bottom', fontsize=30)। 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
freqs = [7, 8, 5, 3, 6]
labels = ['😊', '😲', '😂', '😃', '😛']
plt.figure()
p1 = plt.bar(np.arange(len(labels)), freqs)
for rect1, label in zip(p1, labels):
height = rect1.get_height()
plt.annotate(
label,
(rect1.get_x() + rect1.get_width() / 2, height + .05),
ha="center", va="bottom", fontsize=30
)
plt.show()
आउटपुट
बार चार्ट जहां प्रत्येक बार के ऊपर एक इमोजी लेबल है।