Matplotlib में हैच डेंसिटी कम करने के लिए, हम निम्न चरण अपना सकते हैं:
- फिगर साइज सेट करें और सबप्लॉट्स के बीच और आसपास पैडिंग एडजस्ट करें।
- डेंसिटी ओवरराइड करने के लिए एक कस्टमाइज़्ड हॉरिजॉन्टल हैच क्लास बनाएं।
- हॉरिजॉन्टल हैच क्लास को जोड़ें।
- एक नया फिगर बनाएं या मौजूदा फिगर को एक्टिवेट करें।
- सबप्लॉट व्यवस्था के हिस्से के रूप में फिगर में एक 'ax1' जोड़ें।
- डेटा पॉइंट्स की लिस्ट बनाएं।
- x और y डेटा पॉइंट्स के साथ बार प्लॉट बनाएं, hatch='o', color='green' और edgecolor='red' के साथ।
- फिगर डिस्प्ले करने के लिए show() मेथड का उपयोग करें।
उदाहरण
from matplotlib import pyplot as plt, hatch
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
class MyHorizontalHatch(hatch.HorizontalHatch):
def __init__(self, hatch, density):
char_count = hatch.count('o')
if char_count > 0:
self.num_lines = int((1.0 / char_count) * density)
else:
self.num_lines = 0
self.num_vertices = self.num_lines * 2
super().__init__(hatch, density)
hatch._hatch_types.append(MyHorizontalHatch)
fig = plt.figure()
ax1 = fig.add_subplot(111)
x = [3, 6, 1]
y = [4, 6, 1]
ax1.bar(x, y, color='green', edgecolor='red', hatch="o", lw=1., zorder=0)
plt.show()
आउटपुट
