Python数据科学库第一天

matplotlib用于画图
numpy用于处理数字
pandas不光处理数字,还能处理字符串,时间等

matplotlib绘图:

#折线图
from matplotlib import pyplot as pl
x = range(2, 28, 2)
y = [15, 13, 14, 5, 17, 20, 25, 26, 26, 24, 22, 18, 15]
pl.plot(x, y)
pl.show()

#增加细节
from matplotlib import pyplot as pl
fig = pl.figure(figsize=(15, 10), dpi=60) #设置图像比例,15是横向大小,10是竖向大小,dpi控制图片整体缩放,数值越高,图片越大
x = range(2, 28, 2)
y = [15, 13, 14, 5, 17, 20, 25, 26, 26, 24, 22, 18, 15]
pl.plot(x, y)
pl.xticks(range(2, 28)[::2]) #x轴刻度设置
pl.yticks(range(0, 30)[::2]) #y轴刻度设置
# pl.savefig('') 用来保存图片到本地
pl.show()

#练习,绘制两小时内每分钟的气温变化
import random
from matplotlib import font_manager
from matplotlib import pyplot as pl

# 设置显示中文
# cmd中fc-list :lang=zh可以查询系统中的所有中文字体
my_font = font_manager.FontProperties(fname='C:/Windows/fonts/msyhl.ttc')

a = [random.randint(20, 35) for i in range(120)]
x = range(0, 120)
fig = pl.figure(figsize=(20, 10), dpi= 60)
pl.plot(x, a)

# 调整x轴和y轴
_x = list(x)
x_labels = ['10点{}分'.format(i) for i in range(60)]
x_labels += ['11点{}分'.format(i) for i in range(60)]
# 取步长数字和字符串要一一对应,而且数据长度要想等,rotation是旋转坐标轴的参数
pl.xticks(_x[::5], x_labels[::5], rotation=45, fontproperties = my_font)

# 添加描述信息
pl.xlabel('时间', fontproperties = my_font)
pl.ylabel('温度 单位(℃)', fontproperties = my_font)
pl.title('十点到十二点每分钟的气温变化情况', fontproperties = my_font)

pl.show()

#练习
from matplotlib import font_manager
from matplotlib import pyplot as pl

# 设置显示中文
# cmd中fc-list :lang=zh可以查询系统中的所有中文字体
my_font = font_manager.FontProperties(fname='C:/Windows/fonts/msyhl.ttc')

a = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
x = range(11, 31)
fig = pl.figure(figsize=(20, 10), dpi= 60)
pl.plot(x, a)

# 调整x轴和y轴
_x = list(x)
x_labels = ['{}岁'.format(i) for i in range(11, 31)]
# 取步长数字和字符串要一一对应,而且数据长度要想等,rotation是旋转坐标轴的参数
pl.xticks(_x, x_labels, rotation=45, fontproperties = my_font)

# 添加描述信息
pl.xlabel('年龄', fontproperties = my_font)
pl.ylabel('对象个数', fontproperties = my_font)
pl.title('从十一岁到三十岁的每年对象个数', fontproperties = my_font)

pl.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值