散点图是scatter
,下面还是通过之前的微博表格来进行绘制。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import os
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
df = pd.read_excel(r"D:\\Python\\datalearning\\matplotlib绘图\\weibo.xlsx", )
df.head()
image.png
df.dropna(axis=0)
fig = plt.figure(figsize=(8,4))
plt.scatter(
df['新关注人数'],
df['净增人数'],
c = 'maroon'
)
plt.title("公众号新关注人数和净增人数散点图")
plt.xlabel("新增人数")
plt.ylabel("净增人数")
fig.autofmt_xdate(rotation = 45)
plt.show()
image.png
自己设置xy轴的范围大小,去掉异常点,使得数据分布更加合理
fig = plt.figure(figsize=(8,4))
plt.scatter(
df['新关注人数'],
df['净增人数'],
c = 'maroon'
)
plt.title("公众号新关注人数和净增人数散点图")
plt.xlabel("新增人数")
plt.ylabel("净增人数")
plt.xlim((15, 55))
plt.ylim((0, 50))
fig.autofmt_xdate(rotation = 45)
plt.show()
image.png