forked from luzyPer/pyutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fig.py
More file actions
52 lines (41 loc) · 1.36 KB
/
test_fig.py
File metadata and controls
52 lines (41 loc) · 1.36 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
"""
简单测试示例 - 验证fig.py功能
"""
import numpy as np
import matplotlib.pyplot as plt
from fig import PlotConfig, close
def simple_test():
"""简单测试fig.py的基本功能"""
print("开始测试fig.py...")
try:
# 创建配置
config = PlotConfig(config_name='manuscript_single')
print("✓ 配置创建成功")
# 创建简单图形
fig, ax = config.get_simple()
print("✓ 图形和坐标轴创建成功")
# 生成测试数据
x = np.linspace(0, 2*np.pi, 50)
y = np.sin(x)
# 绘图
ax.plot(x, y, 'b-', linewidth=2, label=r'$y = \sin(x)$')
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$y$')
ax.set_title('Test Plot')
ax.legend()
ax.grid(True, alpha=0.3)
print("✓ 绘图完成")
# 保存
# plt.savefig('test_plot.png', dpi=150, bbox_inches='tight')
plt.savefig('test_plot.pdf', bbox_inches='tight')
print("✓ 图片保存成功: test_plot.pdf")
# 关闭
close(fig)
print("✓ 图形关闭成功")
print("\n测试完成!fig.py工作正常。")
except Exception as e:
print(f"✗ 测试失败: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
simple_test()