Repository navigation
Expand file tree
/
Copy pathplot.py
More file actions
85 lines (74 loc) · 2.66 KB
/
Copy pathplot.py
File metadata and controls
85 lines (74 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# import pandas as pd
# import matplotlib.pyplot as plt
#
# # ========== 1. 参数自己改这里 ==========
# csv_path = r"E:\csv\features\ad1.csv" # 换成你的文件路径
# start_row = 10000 # 起始行号(含)
# end_row = 10500 # 结束行号(含)
# # =======================================
#
# # 2. 读文件:GBK 编码,带表头
# df = pd.read_csv(csv_path, encoding='gbk')
#
# # 3. 提取第 5 列开始连续 30 列(pandas 从 0 开始计数)
# vib_cols = df.iloc[:, 4:34] # 4 是第 5 列,4+30=34 不含
# vib_cols = vib_cols.iloc[start_row:end_row+1] # 切片行
#
# # 4. 画图:6 张图,每张 5 个子图
# big_figs = 6 # 30 / 5
# sub_per_fig = 5 # 每图 5 个子图
#
# for fig_idx in range(big_figs):
# # 新建一张大画布:5 行 1 列
# fig, axes = plt.subplots(sub_per_fig, 1,
# figsize=(18, 14),
# sharex=True)
# if sub_per_fig == 1:
# axes = [axes] # 兼容只有 1 个子图的情况
#
# # 计算本次要画的列号
# start_col = fig_idx * sub_per_fig
# end_col = start_col + sub_per_fig
# cols_now = vib_cols.iloc[:, start_col:end_col]
#
# for ax, col in zip(axes, cols_now.columns):
# ax.plot(cols_now.index - start_row, cols_now[col], linewidth=0.5)
# ax.set_ylabel('Amplitude')
# ax.set_title(f'Channel {col}')
# ax.grid(True)
#
# # 最底下子图加横轴标签
# axes[-1].set_xlabel('Sample Index')
#
# # 调整布局,避免重叠
# fig.tight_layout()
# plt.show()
import pandas as pd
import matplotlib.pyplot as plt
# 设置 Matplotlib 字体以支持中文显示
plt.rcParams['font.family'] = 'Times New Roman ,SimSun'
plt.rcParams['mathtext.fontset'] = 'stix'
plt.rcParams['axes.unicode_minus'] = False
# ========== 1. 自己改这里 ==========
csv_path = r"E:\csv\AD-1-combined.csv" # 路径
start_row = 10000 # 起始行号(含)
end_row = 11000 # 结束行号(含)
# ===================================
# 2. 读文件
df = pd.read_csv(csv_path, encoding='gbk')
# 3. 取第 2 列开始连续 6 列
sig = df.iloc[start_row:end_row+1, 1:7]
# 全局字体放大加粗
plt.rcParams.update({'font.size': 18,
'font.weight': 'bold'})
# 4. 一张大图:6 行 1 列
fig, axes = plt.subplots(6, 1, figsize=(12, 10), sharex=True)
for ax, col in zip(axes, sig.columns):
ax.plot(sig.index - start_row, sig[col], linewidth=0.5)
ax.set_ylabel('Amplitude')
ax.set_title(f'Channel {col}')
ax.grid(True)
# 最底横轴
axes[-1].set_xlabel('Sample Index')
plt.tight_layout()
plt.show()