← Back to Pandas Course | Chapter 12: Visualization Basics | Lesson 5 of 6

Plots को Customize करना

Titles, labels, colours और sizes plot arguments या returned Axes से सेट किए जाते हैं।

In this page:

  1. Customizing plots
Syntax
python
df.plot(title="title", xlabel="x label", ylabel="y label",
        color="color", figsize=(width, height), grid=True, legend=True)

Customizing plots

plot() title, xlabel, ylabel, color, figsize, grid और legend accept करता है। ज़्यादा control के लिए, returned Axes पर ax.set_title जैसे methods call करें। plt.tight_layout spacing को व्यवस्थित करता है।

Note: aspect ratio control करने के लिए figsize=(8, 4) सेट करें।

उदाहरण: Customizing plots

python
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame({"month": [1, 2, 3], "sales": [10, 15, 12]})
ax = df.plot(x="month", y="sales", title="Monthly sales", color="green", figsize=(6, 3), grid=True)
ax.set_xlabel("Month")
ax.set_ylabel("Units")
print(ax.get_title(), "|", ax.get_xlabel(), "|", ax.get_ylabel())

# Output:
# Monthly sales | Month | Units
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. #}
आम गलतियां
  1. गलत object पर labels सेट करना
  2. कई lines पर legends भूल जाना
  3. tight_layout के बिना तंग figures
चैप्टर सारांश
  • Arguments titles और labels सेट करते हैं
  • Axes बेहतर control देता है
  • figsize size सेट करता है
  • tight_layout spacing ठीक करता है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.