5.4.15 · HinglishScientific Computing (Python)

Matplotlib — figure - axes architecture

1,597 words7 min readRead in English

5.4.15 · Coding › Scientific Computing (Python)


KYA hain yeh pieces?

Figure — Matplotlib — figure - axes architecture

KAISE banate hain inhe? (do interfaces)

"From scratch" equivalence derive karna

plt.plot(x, y) ek single plot ke liye ax.plot(x, y) ke exactly same kyun hai? Kyunki plt.plot literally yeh hai:

gca().plot(x, y)      # gca = "get current Axes"; agar koi nahi hai toh ek banata hai

Toh pyplot ek thin wrapper hai jo same Axes method call karta hai jo bhi Axes "current" hai uspe. OO style bas yeh guessing hata deta hai ki kaun sa Axes current hai.


Worked examples


Common mistakes (steel-manned)



Recall Feynman: ek 12-saal ke bacche ko samjhao

Ek scrapbook page imagine karo (woh hai Figure). Page pe aap kuch photo frames chipkate ho (woh hain Axes — har frame ek choti si picture hai apne upar/neeche aur baaye/daaye rulers ke saath). Har frame ke andar aap cheezein draw karte ho: lines, dots, ek caption (woh hain Artists). Matplotlib kabhi kabhi "woh frame jo maine aakhri baar touch kiya" yaad rakhta hai toh agar aap drawing karte raho, sab kuch usi frame mein pile ho jaata hai. Safe rehne ke liye, exactly woh frame point karo jo aap chahte ho — "frame number 3, yahan draw karo!" — na ki yeh umeed rakho ki usne sahi guess kar liya.


Active recall

Matplotlib ka top-level container kaun sa hai jo ek saved image banta hai?
Figure.
Matplotlib mein "Axes" ka matlab kya hai?
Ek single plot/subplot apne x aur y coordinate system ke saath (NA ki do axis lines).
Matplotlib mein "Axis" (singular) kya hai?
Ek direction ka scale, ticks aur tick-labels manage karne wala (jaise ax.xaxis).
Artist kya hai?
Har drawable cheez ka base class: Line2D, Text, Patch, Spine, Tick, Legend, etc.
Outermost-to-innermost container hierarchy?
Figure ⊃ Axes ⊃ Artist (Axis ke saath jo Axes ke andar per-direction manager hai).
plt.subplots(2,3) kya return karta hai?
Ek Figure aur Axes objects ka 2×3 NumPy array.
Multi-panel figures ke liye OO interface preferred kyun hai?
Yeh har Axes ko explicitly address karta hai (ax[r,c]) toh koi ambiguous "current" Axes nahi hota.
plt.plot(x,y) kis OO call ka shorthand hai?
gca().plot(x,y) — current Axes pe plotting (agar koi nahi hai toh create hota hai).
savefig kis object pe call karte hain?
Figure pe: fig.savefig("out.png").
OO style vs pyplot mein x-label kaun sa method set karta hai?
OO: ax.set_xlabel(...); pyplot: plt.xlabel(...).
fig.suptitle kya karta hai?
Poore Figure ke liye ek title add karta hai, jo uske saare Axes span karta hai.
Koi error nahi hone ke bawajood figure blank kyun dikh sakta hai?
Aapne hidden current Axes pe plot kiya, apne ax pe nahi; ya plt.show()/savefig bhool gaye.

Connections

  • Matplotlib — pyplot vs object-oriented API
  • Matplotlib — subplots and GridSpec layout
  • Matplotlib — Artists, Line2D and styling
  • NumPy — arrays as plot data
  • Saving figures — dpi, formats, bbox
  • Scientific Computing (Python)

Concept Map

contains list of

manages

holds

base class of

is an

calls

returns current

creates both

returns grid of

caused by wrong

Figure fig - whole canvas

Axes ax - one plot region

Axis - xaxis and yaxis

Artist - drawable base class

Line2D, Text, Spine, Tick

Pyplot interface plt.plot

OO interface fig, ax = plt.subplots

gca - get current Axes

Container confusion bugs