我在获取 x、y、z 轴上的数据时遇到问题。下面是我的代码。我为不同轴定义范围(dx,dy.dz)的方式是否有任何问题。
result=[['122', '109', '2343', '220', '19'],
['15', '407', '37', '10', '102'],
['100', '100', '100', '100', '100'],
['113', '25', '19', '31', '112'],
['43', '219', '35', '33', '14'],
['132', '108', '256', '119', '14'],
['22', '48', '352', '51', '438']]
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.dates as dates
def format_date(x, pos=None):
return dates.num2date(x).strftime('%m/%d/%Y')
fig=plt.figure()
ax1=fig.add_subplot(111,projection='3d')
xpos=[10/11/2013,10/12/2013,10/13/2013,10/14/2013,10/15/2013]
ypos=['A1','C1','G1','M1','M2','M3','P1']
zpos=result
dx=[5]
dy=[7]
dz=[7]
ax1.w_xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
ax1.bar3d(xpos,ypos,zpos,dx,dy,dz,color='#00ceaa')
plt.show()
我收到以下错误:
TypeError Traceback (most recent call last)
<ipython-input-45-02cd8e7ee228> in <module>()
18 dz=[17]
19 ax1.w_xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
---> 20 ax1.bar3d(xpos,ypos,zpos,dx,dy,dz,color='#00ceaa')
21 plt.show()
C:\Users\Andalib\Anaconda\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in bar3d(self, x, y, z, dx, dy, dz, color, zsort, *args, **kwargs)
2316 maxx = max(xi + dxi, maxx)
2317 miny = min(yi, miny)
-> 2318 maxy = max(yi + dyi, maxy)
2319 minz = min(zi, minz)
2320 maxz = max(zi + dzi, maxz)
TypeError: cannot concatenate 'str' and 'int' objects