经过两天的学习,个人发现Matplotlib库就是一个小工具,之后会跟数据分析有关系,如果对这个库感兴趣的同学,可以直接到Matplotlib官网看examples,里面有很多优秀的例子,官网地址:https://matplotlib.org/gallery/index.html
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()
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()
简书链接:https://www.jianshu.com/u/43dde81143d0
CSDN链接:https://blog.csdn.net/qq_33543737
知乎:https://www.zhihu.com/people/feng-yi-yang-de-nan-ren/activities
微信公众号:TSL00001111