Python数据可视化库-Matplotlib——直方图散点图

版权声明:禁止转载至其它平台,转载至博客需带上此文链接。 https://blog.csdn.net/qq_41841569/article/details/86535699

经过两天的学习,个人发现Matplotlib库就是一个小工具,之后会跟数据分析有关系,如果对这个库感兴趣的同学,可以直接到Matplotlib官网看examples,里面有很多优秀的例子,官网地址:https://matplotlib.org/gallery/index.html

学习Python中有不明白推荐加入交流群
                号:960410445
                群里有志同道合的小伙伴,互帮互助,
                群里有不错的视频学习教程和PDF!

import numpy as np
from matplotlib import pylab as plt
import pandas as pd

plt.rcParams['font.sans-serif']=['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号

titanic = pd.read_csv("train.csv") # 获取数据
age = titanic["Age"] # 获取年龄字段
ageIsnull = pd.isnull(age) # 找到缺失值
good_ages = titanic["Age"][ageIsnull == False] # 去除缺失值

直方图数据,指定直方图的条形数为20个,指定填充色,指定直方图的边界色,为直方图呈现标签

plt.hist(good_ages, bins = 20, color = 'pink', edgecolor = 'black', label = '直方图')
plt.legend(loc = 0)
plt.title("润博的学习笔记")

plt.show()

image.png

image.png


print("********散点图*******")
fig, ax = plt.subplots()
ax.scatter(titanic["PassengerId"], titanic["Age"])

ax.set_xlabel("PassengerId")
ax.set_ylabel("Age")
ax.set_title(u"润博的学习笔记")
plt.show()

image.png

猜你喜欢

转载自blog.csdn.net/qq_41841569/article/details/86535699