Skip to main contentSkip to solution

Consider the python code as follows:

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.plot(df.weight,df.height,marker='*',markersize=10)

plt.show()

Which of the chart will be displayed as output?

Solution

✅ Correct Option: 1

plt.plot() draws a line chart by default, joining the data points with straight line segments. The marker='*' argument only adds a star at each point and does not change the chart type. Here weight is on the x-axis and height on the y-axis, so the output is a line chart with star markers.


Option 3: a scatter chart needs plt.scatter(). Adding markers to plt.plot() does not turn it into one, because the points are still joined by a line.

Options 2 and 4: these need plt.bar() and plt.hist() respectively.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question