python数据分析与展示笔记(第二周 数据展示)


内容来自中国大学MOOC,北京理工大学,python数据分析与展示课程,侵删。
如有错误,烦请指出。


python数据分析与展示笔记 第二周 数据展示

一、Matplotlib 库

import matplotlib.pyplot as plt
1. pyplot 的绘图函数

1.1 - 1 - plt.plot()1.1 - 2 - plt.plot() 的 format_string 颜色字符1.1 - 3 - plt.plot() 的 format_string 风格字符1.1 - 4 - plt.plot() 的 format_string 标记字符1.1 - 5 - plt.plot() 的 **kwargs1.1 - 6 - 多组相同风格1.1 - 7 - 多组不同风格标记

  • plt.plot(y) 只有一个输入列表或数组时,参数被当作 Y 轴,X 轴以索引自动生成
  • plt.plot(x,y) 当有两个以上参数时,按照 X 轴和 Y 轴顺序绘制数据点
    plt.plot(y)plt.plot(x,y)
2. pyplot 的中文显示 - 方法一
import matplotlib
matplotlib.rcParams['font.family']='SimHei'
  • rcParams 的属性:
    2 - 1 - rcParams 的属性
  • 中文字体的种类:
    2 - 2 - 中文字体的种类
  • 实例:
    2 - 3 - 实例
3. pyplot 的中文显示 - 方法二

在有中文输出的地方,增加一个属性 fontproperties

3 - 实例

4. pyplot 的文本显示函数

4 - 1 - 文本显示函数4 - 2 - 实例

5. pyplot 的子绘图区域

(1) plt.subplot()
5.1 - 1 - subplot5.1 - 2- 实例(2) plt.subplot2grid()
5.2 - 1 - plt.subplot2grid5.2 - 2 - 实例(3) GridSpec 类
5.3 - 1 - gridspec 类

二、实例二:引力波的绘制

1. 代码
'''实例二:引力波的绘制'''

import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile

rate_h, hstrain = wavfile.read(r"H1_Strain.wav","rb")
rate_l, lstrain = wavfile.read(r"L1_Strain.wav","rb")
reftime, ref_H1 = np.genfromtxt('wf_template.txt').transpose()

htime_interval = 1/rate_h
ltime_interval = 1/rate_l
fig = plt.figure(figsize=(12, 6))

# 丢失信号起始点
htime_len = hstrain.shape[0]/rate_h
htime = np.arange(-htime_len/2, htime_len/2, htime_interval)
plth = fig.add_subplot(221)
plth.plot(htime, hstrain, 'y')
plth.set_xlabel('Time (seconds)')
plth.set_ylabel('H1 Strain')
plth.set_title('H1 Strain')

ltime_len = lstrain.shape[0]/rate_l
ltime = np.arange(-ltime_len/2, ltime_len/2, ltime_interval)
pltl = fig.add_subplot(222)
pltl.plot(ltime, lstrain, 'g')
pltl.set_xlabel('Time (seconds)')
pltl.set_ylabel('L1 Strain')
pltl.set_title('L1 Strain')

pltref = fig.add_subplot(212)
pltref.plot(reftime, ref_H1)
pltref.set_xlabel('Time (seconds)')
pltref.set_ylabel('Template Strain')
pltref.set_title('Template')
fig.tight_layout()

plt.savefig("Gravitational_Waves_Original.png")
plt.show()
plt.close(fig)
2. 代码分析

(1) 产生时间序列
2.2 - 1 - 产生时间序列(2) 读取应变数据
2.2 - 2 - 读取应变数据(3)绘制 H1 Strain
2.2 - 3 - 绘制 H1 Strain(4) 绘制 L1 Strain & Template
2.2 - 4 - 绘制 L1 Strain & Template(5) 显示并保存图像
2.2 - 5 - 显示并保存图像

3. 引力波绘制结果展示

2.3 - 引力波绘制结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值