Pandas मल्टी-इंडेक्स डेटा फ्रेम को सभी xticks के साथ प्लॉट करने के लिए, हम निम्नलिखित चरण अपना सकते हैं:
- फिगर का आकार सेट करें और सबप्लॉट के बीच और आसपास पैडिंग समायोजित करें।
- 1000 सैंपल डेटा के साथ इंडेक्स मान बनाएं।
- एक्सिस लेबल के साथ एक-आयामी ndarray बनाएं।
- सीरीज का माध्य मान प्राप्त करें।
- g डेटाफ्रेम प्लॉट करें।
- वर्तमान एक्सिस पर टिक्स और टिकलेबल सेट करें।
- फिगर प्रदर्शित करने के लिए show() मेथड का उपयोग करें।
उदाहरण
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
idx = pd.date_range("2020-01-01", periods=1000)
val = np.random.rand(1000)
s = pd.Series(val, idx)
g = s.groupby([s.index.year, s.index.month]).mean()
ax = g.plot()
ax.set_xticks(range(len(g)))
ax.set_xticklabels(["%s-%02d" % item for item in g.index.tolist()], rotation=45, ha='center')
plt.show()आउटपुट
