Python plt.savefig():ValueError:仪表板列表中的所有值都必须为正值
在下面的链接上运行代码会导致错误。至于与图像有关的东西,我不知道“破折号列表”是什么Python plt.savefig():ValueError:仪表板列表中的所有值都必须为正值,python,matplotlib,matplotlib-basemap,Python,Matplotlib,Matplotlib Basemap,在下面的链接上运行代码会导致错误。至于与图像有关的东西,我不知道“破折号列表”是什么 matplotlib.pyplot as plt ... plt.savefig('tutorial10.png',dpi=300) 返回错误的段: --------------------------------------------------------------------------- ValueError Trace
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
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
60 ax.添加_集合(行)
61
-->62 plt.savefig('tutorial10.png',dpi=300)
63
64 plt.show()
...
C:\Anaconda\lib\site packages\matplotlib\backend\u base.pyc in set\u破折号(self、破折号偏移、破折号列表)
902 dl=np.asarray(破折号列表)
903如果np.any(dl 904 raise VALUE ERROR(虚线列表中的所有值必须为正值))
905自身。破折号=破折号偏移,破折号列表
906
在您链接的代码中,有以下几行:
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)
在这些行中,参数
破折号
设置为[1,0]
。关于错误消息,数组破折号
中的所有值必须严格为正。这就是为什么会出现异常(数组破折号
包含零)。在链接的代码中,有以下行:
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)
在这些行中,参数
破折号
设置为[1,0]
。关于错误消息,数组破折号
中的所有值必须严格为正。这就是为什么会出现异常(数组破折号
包含零).您在第一个代码块中键入了dip
而不是dpi
(但在回溯中似乎键入正确)。您在第一个代码块中键入了dip
而不是dpi
(但在回溯中似乎键入正确)。谢谢。将“破折号=[1,0]”更改为“破折号=[1,1]”将“破折号=[1,0]”更改为“破折号=[1,1]”以使其运行。