我想通过添加额外的列扩展这个工作代码..下面给出的示例文件..现在的问题是,我需要把所有的项目在框中括号[]作为一列像总列数为6。如何编写一个条件来继续它?如何通过指定字符拆分python脚本中的列?
Sample.txt的
7.020000 993.000000 755.000000 FAIL 3 [ 62 02 01 23 26 30 35 C0 C0 C0 C0 ]
7.020000 993.000000 803.000000 FAIL 5 [ 62 02 01 23 26 30 35 C0 C0 C0 C0 ]
7.020000 993.000000 811.000000 FAIL 2 [ 62 02 01 23 26 30 35 C0 C0 C0 C0 ]
7.020000 993.000000 828.000000 PASS 1 []
7.020000 993.000000 876.000000 PASS 6 []
7.020000 993.000000 894.000000 FAIL 3 [ 62 02 01 23 26 30 35 C0 C0 C0 C0 ]
7.020000 993.000000 913.000000 FAIL 5 [ 62 02 01 23 26 30 35 C0 C0 C0 C0 ]
7.020000 993.000000 954.000000 FAIL 2 [ 62 02 01 23 26 30 35 C0 C0 C0 C0 ]
任何建议将是有益的!!!!!!!!
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure(figsize=(20, 20))
fig.savefig('Test2.png')#, dpi=600)
ax = Axes3D(fig) # ax = fig.add_subplot(111, projection='3d')
ax.set_title("Plot 3d",fontsize=14)
ax.set_xlabel('Voltage (V)', fontsize=12)
ax.set_ylabel('Pulse Delay(ms)', fontsize=12)
ax.set_zlabel('Pulse Width(ms)', fontsize=12)
ax.grid(True, linestyle='-', color='0.75')
data = np.genfromtxt('./Sample.txt', dtype=[('col1', 'f8'), ('col2', 'i16'), ('col3', 'i16'), ('col4', 'S15'), ('col5', 'i16'), ('col6', 'S24')])
m = data["col4"]
data1 = data[m == "PASS"]
data2 = data[m != "PASS"]
for dat, color in [(data1, 'g'), (data2, 'r')]:
# Don't forget that having empty data columns may raise exceptions ...
try:
x, y, z = dat['col1'], dat['col2'], dat['col3']
ax.scatter(xs=x, ys=y, zs=z, s=50, c=color, marker='o', linewidths=0)
except:
pass
plt.show()
Thnx rczajka ...代码工作正常..唯一的事情是,当我运行一个大的txt文件时,我面对一些滞后的性能...... – User