I was facing a problem in plotting a 3d surface plot by reading a text file. The problem is, I am using a different datatypes, like float, int and string.. I have attached the code with the sample data to be parsed.. I would appreciate with any comments with the code to make it functional...
The error which I got now is ValueError: size of tuple must match number of fields.
Thnx in advance....
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from numpy import genfromtxt
fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(111, projection='3d') #ax = Axes3D(fig)
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')
x,y,z,m =genfromtxt('sample.txt', dtype=[('col1', 'f15'), ('col2', 'i15'), ('col3', 'i15'), ('col4', 'S15')], unpack=True)
use_colours = []
for tmp in m:
if tmp=='PASS':
use_colours.append('g')
else:
use_colours.append('r')
ax.scatter(x,y,z, s=50, c=use_colours, marker = 'o', linewidths=0);
plt.show()
sample.txt
6.000000 15.000000 21.000000 PASS
6.000000 15.000000 53.000000 PASS
6.000000 15.000000 91.000000 PASS
6.000000 15.000000 104.000000 PASS