Informatics Practices

Plot a line chart for depicting the population for the last 5 years as per the specifications given below:

  • plt.title("My Title") will add a title "My Title" to your plot.

  • plt.xlabel("Year") will add a label "Year" to your X-axis.

  • plt.ylabel("Population") will add a label "Population" to your Y-axis.

  • plt.yticks([1, 2, 3, 4, 5]) set the numbers on the Y-axis to be 1, 2, 3, 4, 5. Pass it and label as a second argument. For example, if we use this code plt.yticks([1, 2, 3, 4, 5], ["1M", "2M", "3M", "4M", "5M"]), it will set the labels 1M, 2M, 3M, 4M, 5M on the Y-axis.

  • plt.xticks() — works the same as plt.yticks(), but for the X-axis.

PyPlot

1 Like

Answer

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4, 5], ['1M', '2M', '3M', '4M', '5M'])
plt.title("My Title")
plt.xlabel("Year")
plt.ylabel("Population")
plt.xticks([1, 2, 3, 4, 5], ["2019", "2020", "2021", "2022", "2023"])
plt.yticks([1, 2, 3, 4, 5], ['1M', '2M', '3M', '4M', '5M'])
plt.show()
Output
Plot a line chart for depicting the population for the last 5 years as per the specifications given below: Data Visualization using Matplotlib, Informatics Practices Preeti Arora Solutions CBSE Class 12

Answered By

3 Likes


Related Questions