Skip to content
Think & Reflect · Q6

Q.What effect did ‘legend= False’ in Program 4.17 have on the output?
[Context: Program 4-17 is:
import pandas as pd
import matplotlib.pyplot as plt
df=pd.DataFrame({'GeoArea':[83743,78438,22327,22429,21081,16579,10486],'ForestCover':[67353,27692,17280,17321,19240,13464,8073]}, index=['Arunachal Pradesh','Assam','Manipur','Meghalaya','Mizoram','Nagaland','Tripura'])
df.plot(kind='pie',y='ForestCover', title='Forest cover of North Eastern states',legend=False)
plt.show()]

Punjab PsebTextbookSubjective· 2mImportance★★★★★est
98% · 43/44 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Setting legend=False in a pie chart removes the legend box, leaving only the pie slices with their labels.

Why legend=False matters in pie charts

A pie chart already labels each slice directly (either on the slice itself or with leader lines), showing both the category name and often the percentage or value. The legend, which sits separately and maps colors to categories, becomes redundant — it duplicates information already visible on the chart.

When you call df.plot(kind='pie', y='ForestCover') without any legend parameter, pandas defaults to legend=True and draws a legend box listing all seven states with their corresponding colors. This clutters the figure: you now have state names appearing twice — once on or near each slice, and again in the legend.

Setting legend=False suppresses that redundant box. The pie chart still displays each state's name next to its slice (pandas does this automatically for pie charts), so you lose no information. The result is a cleaner, less cluttered visualization focused entirely on the proportions.

What the output looks like with and without the legend

With legend=True (the default):

  • A pie chart with seven slices, one per North Eastern state, sized by forest cover.
  • Each slice is labeled with the state name (e.g., "Arunachal Pradesh") and possibly its value or percentage.
  • A legend box appears (usually to the right or below), listing all seven state names again with colored squares matching the slice colors.
  • The chart title "Forest cover of North Eastern states" appears at the top.

With legend=False (as in Program 4.17):

  • The same pie chart with seven slices.
  • Each slice still carries its state-name label.
  • No legend box — the figure is cleaner, with more space for the pie itself.
  • The title remains. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.