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?
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
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.
Related questions:
2026: 23 May Shift 2
2026: 20 May Shift 1
2025: 13 May Shift 2
2025: 3 June Shift 2
2026: 21 May Shift 1