上QQ阅读APP看书,第一时间看更新
How it works...
The explanation for the code follows:
- plt.figure(figsize=(10,6)) overwrites the default figure size with size (10, 6).
- pd.read_excel() reads the data and assigns values to the x and y axes coordinates.
- plt.scatter(x,y) plots the scatter plot.
- plt.xlabel() and plt.ylabel() set x and y axes labels for better readability.
Display the graph on the terminal. You should see the following chart:
It is clearly visible that there is no relationship between the age and the weight of people, as the points are scattered. If a correlation is present between the two elements depicted, we would observe a pattern of a straight line or a curve.
The previous graphs could have been plotted with the plt.plot() method also. The plt.scatter() method has a lot more flexibility to customize each of the points with different sizes, colors, and so on, which we will observe in the bubble plot section. However, this flexibility comes at the cost of performance. For larger datasets, the plt.plot() method is lot faster than the plt.scatter() method.