Matplotlib 是 Python 的绘图库
它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案。 它也可以和图形工具包一起使用,如 PyQt 和 wxPython

实例:



pyplot绘图区域


pyplot中的plot()函数







pyplot的中文显示
第一种方法:




第二种方法

pyplot的文本显示



pyplot的子绘图区域


GridSpec类


pyplot的基础图标函数



pyplot饼图的绘制


pyplot直方图的绘制


pyplot极坐标图的绘制


pyplot散点图的绘制

“引力波的绘制”实例



数据源
http://python123.1o/dv/grawave.htmi
http://python123.1o/dv/h1StrainWav
http://python123.io/dv/l1strain.wav
http://python123.1o/dv/wftemplatetxt
实例代码:
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('GW150914_4_NR_waveform_template.txt').transpose()
reftime, ref_H1 = np.genfromtxt('wf_template.txt').transpose() #使用python123.io下载文件
# transpose() 方法是对矩阵进行转置
htime_interval = 1/rate_h
ltime_interval = 1/rate_l
fig = plt.figure(figsize=(12, 6)) # f创建一个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)
网友评论