plt.savefig():ValueError:破折号列表中的所有值都必须为正数

时间:2014-04-08 16:25:49

标签: python matplotlib matplotlib-basemap

在以下链接中运行代码会导致错误。至于与图像有关,我不知道'破折号列表'是

matplotlib.pyplot as plt
...
plt.savefig('tutorial10.png',dpi=300)

返回错误的细分:

    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-21-edce1701d7a3> in <module>()
    60     ax.add_collection(lines)
    61 
--> 62 plt.savefig('tutorial10.png',dpi=300)
    63 
    64 plt.show()

    ...

    C:\Anaconda\lib\site-packages\matplotlib\backend_bases.pyc in set_dashes(self, dash_offset, dash_list)
    902             dl = np.asarray(dash_list)
    903             if np.any(dl <= 0.0):
--> 904                 raise ValueError("All values in the dash list must be positive")
    905         self._dashes = dash_offset, dash_list
    906 

http://www.geophysique.be/2013/02/12/matplotlib-basemap-tutorial-10-shapefiles-unleached-continued/

1 个答案:

答案 0 :(得分:4)

在您链接的代码中,有以下几行:

m.drawparallels(np.arange(y1,y2,2.),labels=[1,0,0,0],color='black',dashes=[1,0],labelstyle='+/-',linewidth=0.2) # draw parallels
m.drawmeridians(np.arange(x1,x2,2.),labels=[0,0,0,1],color='black',dashes=[1,0],labelstyle='+/-',linewidth=0.2)

在这些行中,参数dashes设置为[1,0]。关于您的错误消息,数组dashes中的所有值必须严格为正。这就是您获得异常的原因(您的数组dashes包含零)。