目标图
myplot.png
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.ticker import MultipleLocator, FormatStrFormatter # 坐标轴刻度
# 设置中文字体
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
# read data matrix from file
data1 = np.loadtxt("node2.out")
data2 = np.loadtxt("node3.out")
# plot data 图像大小尺寸
plt.figure(figsize=(6, 4))
# [0,0] 两条坐标轴
plt.plot([-5, 5], [0, 0], color='black') # 横
plt.plot([0, 0], [-100, 100], color='black') # 竖
# 两条线,out 第1列 / 1000,第2列 / 12
plt.plot(data1[:, 1] / 12, data1[:, 0] / 1000, label=u'模拟曲线图', color='blue')
plt.plot(data2[:, 1] / 12, data2[:, 0] / 1000, label=u'试验结果', color='red', linestyle='dashed')
# 左上角标签
plt.legend(loc="upper left", bbox_to_anchor=[0, 1], ncol=2, shadow=True, fancybox=True)
# 添加坐标轴刻度设置
ax = plt.gca()
ax.xaxis.set_major_locator(MultipleLocator(1)) # x轴主刻度为1的倍数
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.xaxis.set_minor_locator(MultipleLocator(0.5)) # x轴次刻度为0.5的倍数
ax.yaxis.set_major_locator(MultipleLocator(50)) # 同x
ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.yaxis.set_minor_locator(MultipleLocator(25))
# 设置坐标轴的范围
plt.xlim(-5, 5)
plt.ylim(-100, 100)
# 设置坐标轴标题
plt.xlabel(u"位移(两端位移角%)")
plt.ylabel(u"荷载(kN)")
# show plot
plt.show()
node2.out(前20行)
2387.78 -0.169173
4769.33 -0.0691726
7144.61 0.0308274
9513.59 0.130827
11876.2 0.230827
14232.5 0.330827
16581.6 0.430827
18921.1 0.530827
21253.3 0.630827
23583.8 0.730827
25904.9 0.830827
28221.3 0.930827
30532.1 1.03083
32836.2 1.13083
34712.5 1.23083
36547.9 1.33083
38185 1.43083
39597.7 1.53083
41006.6 1.63083
42309 1.73083
node3.out
3208.06 -0.199239
6406.83 -0.0992388
9596.24 0.0007612
12776.2 0.100761
15946.7 0.200761
19104.7 0.300761
22253.1 0.400761
25394.7 0.500761
28524.2 0.600761
31646.1 0.700761
34569.7 0.800761
37306.9 0.900761
39691.5 1.00076
41973.6 1.10076
43885.4 1.20076
45733.8 1.30076
47182.9 1.40076
48501.5 1.50076
49623.5 1.60076
50449.3 1.70076