I have three equal-length arrays named ra, ma and op with mostly numbers and few instances when they have 'nan' or 'None' in place of a number. Eg:
ra = [0, 1, 2, nan, 8 , 3, 8, 5]
ma = [3, nan, 5, 8, 9, 6, 4, 10]
op = [7, None, 7, 9, 3, 6, None, 7]
I want to make a 3d plot of the numbers in them. My code is :
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(ra,ma,op)
plt.show()
Everything is fine till I type plt.show() - then it gives me a long list of error which ends like:
"TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'".
May be: It is because of the nan values, but i do not know how to remove them :-/ if i want to remove the nan value from ra (which is the 4th value of list), i will also have to remove the respective 4th values from ma and op. And I can not figure out how to do that or if at all we need to do that.
Can someone please point out where i am going wrong??
nans but aboutNones.itertools.compressis pretty easy:op, ma, ra = zip(*compress(zip(op, ma, ra), op))(this assumesopdoesn't contain zeros. Otherwise replaceopwith(x is not None for x in op). Using an explicit loop you can dofor a, b, c in zip(ra, ma, op)check ifc is not Nonein that case inserta,bandcinto some new lists.