1.

Explain the purpose of the following functions:

Answer»

a. plt.xlabel

b. plt.ylabel

c. plt.title

d. plt.legend( )

e. plt.show( )

After installing Matplotlib, we will begin coding by importing Matplotlib using the command: import matplotlib.pyplot as pit

Now you have imported Matplotlib in your workspace. You need to display the plots. Using Matplotlib from within a Python script, you have to add plt.show( ) method inside the file to display your plot.

With plt.xlabel and plt.ylabel, you can assign labels to those respective axis. Next, you can assign the plot’s title with plt.title, and then you can invoke the default legend with plt

legend( ).

plt.plot (years, total_populations)

plt.title → (“Year vs Population in India”)

plt.xlabel → (“Year”)

plt.ylabel (“Total Population”)

plt.legend( )

plt.show( ) Plt.title( ) → specifies title to the graph 

Plt.xlabel( ) → specifies label for X-axis

Plt.ylabel( ) → specifies label for Y-axis



Discussion

No Comment Found