蟒蛇风玫瑰错误

时间:2014-12-12 20:47:34

标签: python pydev

我是Python新手,并尝试使用此网站上的windrose.py代码创建风玫瑰:http://sourceforge.net/projects/windrose/

以下是我正在运行的代码,我在以下网站找到了示例代码: http://youarealegend.blogspot.com/search/label/windrose

import numpy

from windrose import WindroseAxes
from matplotlib import pyplot as plt
import matplotlib.cm as cm
from numpy.random import random
from numpy import arange 
import windrose as wr


import matplotlib.pyplot as mp
import windrose

#Create wind speed and direction variables
ws = random(500)*6
wd = random(500)*360


#A quick way to create new windrose axes...
def new_axes():
  fig = plt.figure(figsize=(8, 8), dpi=80, facecolor='w', edgecolor='w')
  rect = [0.1, 0.1, 0.8, 0.8]
  ax = WindroseAxes(fig, rect, axisbg='w')
  fig.add_axes(ax)
return ax

#...and adjust the legend box
def set_legend(ax):
  l = ax.legend(axespad=-0.10)
  plt.setp(l.get_texts(), fontsize=8)

wr.wrcontourf(wd, ws)

当我运行此代码时,出现以下错误:

RuntimeWarning: invalid value encountered in rint
  return round(decimals, out)

TypeError: __init__() got an unexpected keyword argument 'axespad'

我已经尝试了很多东西,但无法弄清楚这个代码中的axispad变量是做什么的。任何建议都会有所帮助!

提前谢谢你。

1 个答案:

答案 0 :(得分:6)

尝试更改此行:

l = ax.legend(axespad=-0.10)

到此:

l = ax.legend(borderaxespad=-0.10)

一些背景知识:

随着我的好奇心激动,我决定继续冒险。

根据matplotlib documentationaxespad不是legend函数的有效参数,但是borderaxespad。我还注意到您链接到的文章使用的是matplotlib 0.98.3,这是非常过时的版本(实际上,文档不再可用)。

在我的预感之后,我从here下载了旧来源,这是来自here的新来源,并对两者进行了比较。

事实证明,matplotlib 0.98.3仅引用axespad,而matplotlib 1.4.2仅引用borderaxespad。它们所在的代码几乎完全相同。看起来他们在某些时候向Legend添加了边界功能,并决定相应地重命名参数。

相关问题