python中的matplotlib画散点图(数据分析与可视化)文章来源:https://www.toymoban.com/news/detail-667630.html
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
pd.set_option("max_columns",None)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
#任务三、堆积图
# x=np.arange(5)
# phone=pd.read_csv("D:\培训资料\matplotlib模块\任务驱动\素材\手机年销量.txt")
# phoneName=phone["品牌"]
# month6=phone["6月"]
# month7=phone["7月"]
# month8=phone["8月"]
# month9=phone["9月"]
# plt.stackplot(x,month6,month7,month8,month9,labels=["6月","7月","8月","9月"])
# plt.xticks(x,phoneName)
# plt.xlabel("品牌")
# plt.ylabel("销量")
# plt.legend(loc="upper right")
# plt.show()
df1=pd.DataFrame({
"names":["student"+str(i) for i in range(1,201) ],
"sex":["男"]*200,
"height":np.random.randint(160,199,200),
"weight":np.random.randint(50,100,200)
})
df2=pd.DataFrame({
"names":["student"+str(i) for i in range(1,201) ],
"sex":["女"]*200,
"height":np.random.randint(150,175,200),
"weight":np.random.randint(35,75,200)
})
data=pd.concat([df1,df2])
data=data.sample(frac=0.8)
print(data)
data1=data.query("sex=='男'")
data2=data.query("sex=='女'")
plt.scatter(data1["height"],data1["weight"],color="red")
plt.scatter(data2["height"],data2["weight"],color="blue")
plt.show()
效果图:
结束,再见文章来源地址https://www.toymoban.com/news/detail-667630.html
到了这里,关于python中的matplotlib画散点图(数据分析与可视化)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!