import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import MultipleLocator
def padding_data(x):
array1 = []
up_coefficient = [1.122e-08, - 5.613e-06 , 0.0008606, - 0.0378, 0.4916]
up_coefficient = np.array(up_coefficient)
up_equ = np.poly1d(up_coefficient)
#print('up_equ is :\n', up_equ)
for i in range(0, 13):
x_mid1 = 90 * i / 12 + 39
y_mid1 = x * up_equ(x_mid1)
array1.append(y_mid1)
array1.append(x)
down_coefficient = [-4.203e-09, 3.787e-06, - 0.00124, 0.1677, - 6.957]
down_coefficient = np.array(down_coefficient)
down_equ = np.poly1d(down_coefficient)
#print('down_equ is :\n', down_equ)
for i in range(0, 13):
x_mid2 = 158 * i / 12 + 129
y_mid2 = x * down_equ(x_mid2)
array1.append(y_mid2)
return array1
if __name__ == '__main__':
filename = 'Pu.txt'
amount = []
solve_data = 0.0
with open(filename, 'r') as f: # 1
lines = f.readlines() # 2
for line in lines: # 3
value = [float(s) for s in line.split()] # 4
if value[0] >= 2:
x1 = []
solve_data = value[0]
x1 = padding_data(solve_data)
amount.extend(x1)
else:
amount.append(value[0]) # 5
axis = 0
a_axis = []
for i in range(0, len(amount)):
if i % 5 == 0:
axis += 6
elif i % 5 == 1:
axis += 5
elif i % 5 == 2:
axis += 7
elif i % 5 == 3:
axis += 6
elif i % 5 == 4:
axis += 5
a_axis.append(axis)
plt.plot(a_axis, amount, label='$\mathregular{{Pu}_{94}^{239}}$')
font2 = {'family': 'Times New Roman',
'weight': 'normal',
'size': 15,
}
x_major_locator = MultipleLocator(80)
# Set the spacing on the X-axis to 10 and store it in a variable
ax = plt.gca()
# ax is an example of two axes
ax.xaxis.set_major_locator(x_major_locator)
# Set the main scale on the X-axis to a multiple of 10
plt.ylim(0, 9)
plt.xlim(0, axis)
plt.ylabel("Energy(Mev)", font2)
plt.xlabel("Times(us)", font2)
plt.grid()
plt.legend(loc='upper left')
plt.show()
Python读取txt文件并且画出图像,在曲线label中添加上下标
最新推荐文章于 2023-06-08 15:10:01 发布