Windrose axespad meaning

2.1k views Asked by At

I am new to Python and am attempting to create a wind rose using the windrose.py code found at this website: http://sourceforge.net/projects/windrose/

The following is the code I am running and I found the example code at the following website: 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)

When I run this code, I get the following error:

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

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

Although I've tried a number of things I can't figure out what the axespad variable is doing in this code. Any advice would help!

1

There are 1 answers

0
gcarvelli On

Try changing this line:

l = ax.legend(axespad=-0.10)

to this:

l = ax.legend(borderaxespad=-0.10)

Some background:

With my curiosity piqued, I decided to go on a bit of an adventure.

According to the matplotlib documentation, axespad is not a valid argument to the legend function, but borderaxespad is. I also noticed that the article you linked to was using matplotlib 0.98.3, which is a very outdated version (in fact, documentation isn't available for it anymore).

Following my hunch I downloaded the old source from here, the new source from here, and compared the two.

Turns out that matplotlib 0.98.3 only has references to axespad and matplotlib 1.4.2 only has references to borderaxespad. The code they are in is almost exactly the same. It looks like at some point they added border functionality to Legends and decided to rename the argument accordingly.