From matplotlib library I have imported pyplot module. In that module there is an function plot() that I have used. Now my question is:
Why the plot() function is not within any class? And if it s within any class why didn't we create any object of the class and used the plot() function.
From the official documentation I learned that plot() returns a Line2D object. But the return of the plot() is not stored in any variable, yet we are using show() function. Generally it should be returned_object.show() but again the pyplot module has a show() function that is called without using any object just like plot() function. We are using just pyplot.show() to display the graph. How is it possible. I mean it makes more sense in either returned_object.show() or pyplot.show(the returned object from plot() function). How it shows that particular plot not the other random plot?
I have gone through the example code and plotted successfully. And in order to clear my doubts I have visited the official matplotlib module.
from matplotlib import pyplot as plt
years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]
# create a line chart, years on x-axis, gdp on y-axis
plt.plot(years, gdp, color='green', marker='o', linestyle='solid')
# add a title
plt.title("Nominal GDP")
# add a label to the y-axis
plt.ylabel("Billions of $")
plt.show()