我想通過添加額外的列擴展這個工作代碼..下面給出的示例文件..現在的問題是,我需要把所有的項目在框中括號[]作爲一列像總列數爲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