python - plt.savefig() : ValueError: All values in the dash list must be positive

标签 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/

最佳答案

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

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 包含零)。

关于python - plt.savefig() : ValueError: All values in the dash list must be positive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22942855/

相关文章:

Python 请求 - 使用 multipart/form-data 发布一个 zip 文件

python 2.7 matplotlib pylab : My plot is empty. 如何使数据点显示在图中?

python - 如何为 matplotlib 的 drawgreatcircle 函数制作动画?

python - Python 和 Ruby 中的快速模计算

python - 如何在python中执行两个大pandas文件的交叉连接

python-2.7 - 如何找到shortest_path中的特定点/坐标?

python - 如何使用 pyplot 在线绘图?

python - 平滑 shapefile 输出 - basemap python

python - 消除 Matplotlib/Basemap pcolor 图中的白边

Python成像,调整Turtle Graphics窗口大小