Skip to content
Programs · Program 4-3

Q.(Program 4-3) Consider the average heights and weights of persons aged 8 to 16 stored in the following two lists:
height = [121.9, 124.5, 129.5, 134.6, 139.7, 147.3, 152.4, 157.5, 162.6]
weight = [19.7, 21.3, 23.5, 25.9, 28.5, 32.1, 35.7, 39.6, 43.2]
Plot a line chart where:

(i) x axis will represent weight
(ii) y axis will represent height
(iii) x axis label should be "Weight in kg"
(iv) y axis label should be "Height in cm"
(v) colour of the line should be green
(vi) use * as marker
(vii) marker size as 10
(viii) the title of the chart should be "Average weight with respect to average height"
(ix) line style should be dashed
(x) linewidth should be 2.
Puducherry CbseNCERTSubjective· 5mImportance★★★★★est
11% · 5/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 →

Plot height vs weight from a pandas DataFrame, not raw lists.

import matplotlib.pyplot as plt
import pandas as pd
height=[121.9,124.5,129.5,134.6,139.7,147.3,152.4,157.5,162.6]
weight=[19.7,21.3,23.5,25.9,28.5,32.1,35.7,39.6,43.2]
df=pd.DataFrame({"height":height,"weight":weight})
plt.xlabel('Weight in kg')
plt.ylabel('Height in cm')
plt.title('Average weight with respect to average height')
plt.plot(df.weight,df.height,marker='*',markersize=10,color='green',linewidth=2, linestyle='dashdot')
plt.show()

The book's own technique wraps the height/weight lists in a DataFrame first (df=pd.DataFrame({...})), then plots df.weight/df.height -- not the raw lists directly.

Step by step

  1. height and weight start as two plain Python lists (not yet linked to each other).
  2. pd.DataFrame({"height": height, "weight": weight}) pairs them up column-wise, row by row, so row 0 is always (121.9, 19.7), row 1 is (124.5, 21.3), and so on.
  3. plt.plot(df.weight, df.height, ...) plots WEIGHT on x and HEIGHT on y, per the question's own axis requirement -- note the order is (x, y), so weight comes first.
  4. The style keywords (marker='*', markersize=10, color='green', linewidth=2, …

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.