Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

The following code block draws a scatter plot that depicts the relationship between the age and the weight of people:

  1. Set the figure size (width and height) to (10, 6) inches:
plt.figure(figsize=(10,6))

  1. Read age and weight data from an Excel file:
age_weight = pd.read_excel('scatter_ex.xlsx', 'age_weight')
x = age_weight['age']
y = age_weight['weight']
  1. Plot the scatter plot:
plt.scatter(x, y)
  1. Set x and y axis labels:
plt.xlabel('Age')
plt.ylabel('Weight)
  1. Display the graph:
plt.show()