我使用以下列从uniprot文件构建了一个数据框:
(index(protein_id),length, organism, sequence,acidic, polar,hydrophobic,color,width)
参数acidic
,hydrophobic
和polar
是百分比(即1到100之间的数字),width
介于0-1和color
之间是4个数字的集合,例如:(0.5, 0.0, 0.0, 1.0)
我尝试以下列方式构建3d plot:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
charge_sum = 0
display(df)
for index, record in prot_df.iterrows():
xs=int(record['acidic'])
ys=int(record['polar'])
zs=int(record['hydrophobic'])
cs=record['color']
width=record['width']
ax.bar(xs, ys, zs, zdir='y', color=cs, alpha=width)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
但是我收到以下错误:
>TypeError Traceback (most recent call last)
><ipython-input-190-13bea2286c05> in <module>()
> 18 cs=record['color']
> 19 width=record['width']
>---> 20 ax.bar(xs, ys, zs, zdir='y', color=cs, alpha=width)
> 21
> 22
>C:\Users\Owner\Anaconda2\lib\site-packages\mpl_toolkits\mplot3d\axes3d.pyc in >bar(self, left, height, zs, zdir, *args, **kwargs)
> 2392 patches = super(Axes3D, self).bar(left, height, *args, **kwargs)
> 2393
>-> 2394 zs = _backports.broadcast_to(zs, len(left))
> 2395
> 2396 verts = []
>
>TypeError: object of type 'int' has no len()
有人可以帮助我摆脱这个错误吗?