底图散点图(Matplotlib)-无法设置属性

时间:2018-12-09 23:00:27

标签: python matplotlib matplotlib-basemap scatter

我一直在尝试使用Matplotlib将两个浮点列表添加到散点图。我只是使用大多数默认设置创建了一个底图。但是,每当我尝试运行脚本时,都会出现以下错误。

#!/usr/bin/python

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt


def main():

    wmap = Basemap()

    wmap.drawmapboundary(fill_color='aqua')

   wmap.fillcontinents(color='coral',lake_color='aqua')

    wmap.drawcoastlines()

    locationData = open("locationData", "r")

    lats = []

    lons = []

    ASN = []

    company = []

    fileLine = locationData.readlines()

    for i in fileLine:

        parsedLine = i.split(",")

        lats.append(float(parsedLine[0]))

        lons.append(float(parsedLine[1]))

        ASN.append(parsedLine[2])

        company.append(parsedLine[3])

    locationData.close()

    x,y = wmap(lats,lons)

    wmap.scatter(x,y)

    plt.show()


 if(__name__ == '__main__'):
        main()

我收到错误:

Traceback (most recent call last):
  File "mapGen.py", line 51, in <module>
    main()
  File "mapGen.py", line 45, in main
    wmap.scatter(lats,lons)
  File "/usr/lib/python3.7/site-packages      /mpl_toolkits/basemap/__init__.py", line 563, in with_transform
    return   plotfunc(self,x,y,*args,**kwargs)
  File "/usr/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py", line 3253, in scatter
    self._restore_hold(ax)
  File "/usr/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py", line 3229, in _restore_hold
ax._hold = self._tmp_hold
AttributeError: can't set attribute

我尝试过更改wmap.scatter()的属性和变量,但是错误仍然存​​在,并且我无法找到有关此错误的文档。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

当您要更改的属性是没有setter的属性时,会引发此特定异常。似乎需要更改底图,添加setter将解决该问题。

但是您可以将wmap.scatter(x,y)更改为plt.scatter(x, y)来解决它。