df.plot() की बुनियादी बातें
df.plot() एक line में आपके data से chart बनाता है, पीछे Matplotlib का उपयोग करते हुए।
In this page:
Syntax
df.plot(kind="line")
df["column"].plot(kind="bar")
df.plot() basics
Series और DataFrames दोनों में .plot() method होता है। kind argument chart type चुनता है: line (default), bar, hist, box, scatter और अधिक।
Result एक Matplotlib Axes object है जिसे आप customize कर सकते हैं।
नीचे figure को off-screen render किया गया है ताकि हम पुष्टि कर सकें कि यह काम कर गया।
Note:
scripts में plt.show() call करें; notebooks figures को अपने आप display करते हैं।
उदाहरण: df.plot() basics
import io
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [1, 4, 9, 16]})
ax = df.plot(x="x", y="y")
buf = io.BytesIO()
plt.savefig(buf, format="png")
print(type(ax).__name__)
print("rendered:", buf.getbuffer().nbytes > 0)
# Output:
# Axes
# rendered: True
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- scripts में plt.show भूल जाना
- text columns को plot करना
- Matplotlib install न करना
चैप्टर सारांश
- .plot() data को chart करता है
- kind chart type चुनता है
- यह एक Matplotlib Axes return करता है
- इसके लिए Matplotlib चाहिए
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: