2017-07-13 19 views
-1

我是编码和Python的新手,并且正在努力绘制某些内容。因此,我有两组数据,我使用渐变在地图上进行了绘制(红色和蓝色地图中的两个散点图)。Python TypeError用于为%:'method'和'int'绘制每个第N个值'不受支持的操作数类型'

outputted plot of the first two data sets

fig1=plt.figure() 
ax=plt.axes(projection=ccrs.PlateCarree()) 
ax.coastlines() 
ax.add_feature(cartopy.feature.LAND) 
gl=ax.gridlines(draw_labels = True, linewidth=0.0, color='gray') 
gl.xlabels_top = False 
gl.ylabels_right = False 
plt.scatter(VFX0,VFY0, c=VFF3, s=2, cmap='Reds') 
plt.colorbar(label='High Divergence', shrink=0.6) 
plt.scatter(VBX0,VBY0,c=VBF3, cmap='Blues', s=2) 
plt.colorbar(label='High Convergence', shrink=0.6) 
plt.xlabel('Longitude') 
plt.ylabel('Latitude') 
plt.title('Langrangian Coherent Structures', weight='bold') 
plt.show() 

现在我的第三个数据集,我想补充一点,绘制花车比其他数字的经度和纬度。然而,该数据集是如此之大,如果我只是画出所有这些,如

plt.scatter(fframe.lon, fframe.lat, color='k', s=1) 

我得到的是一个黑色的身影,因为有这么多的浮动。所以,我想要做的就是每10次采用一次浮动和阴谋。所以我试图告诉它采用'fnum',这是浮点数,如果它可以被10整除,那么绘制该图,但忽略其他所有内容。

if fframe.fnum.all%10==0: 
    plt.scatter(fframelon, fframelat, color='k', s=1) 

但是当我这样做,我得到一个错误说

TypeError         Traceback (most recent call last) 
<ipython-input-50-28254189539a> in <module>() 
----> 1 if fframe.fnum.all % 10 == 0: 
     2  plt.scatter(fframelon, fframelat, color='k', s=1) 
     3 plt.xlabel('Longitude') 
     4 plt.ylabel('Latitude') 
     5 plt.title('Langrangian Coherent Structures', weight='bold') 
TypeError: unsupported operand type(s) for %: 'method' and 'int' 

谁能帮我找出其中我的错误是什么?

+1

'fframe.fnum.all'是一种方法。你期望'fframe.fnum.all%10'做什么? –

+1

也许你打算去打电话吗? 'fframe.fnum.all()%10' –

回答

0

在假设fframe.lonframe.lat是列表或一维numpy数组的情况下,可以通过fframe.lon[::n]绘制每个n的点。例如。对于每十分之一,

plt.scatter(fframe.lon[::10], fframe.lat[::10], color='k', s=1) 
+0

完美的工作,谢谢! – Tacha

相关问题