Axespad Windrose meaning
I am new to Python and am trying to create a wind rose using the code windrose.py
found on this site: http://sourceforge.net/projects/windrose/
Below is the code I am running and I found sample code on 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 few things, I can't figure out what the axespad variable does in this code. Any advice would help!
source to share
Try changing this line:
l = ax.legend(axespad=-0.10)
:
l = ax.legend(borderaxespad=-0.10)
Some background:
Curiously, I decided to have a little adventure.
According to the matplotlib documentation , axespad
not a valid function argument legend
, but borderaxespad
is. I also noticed that the article you linked was using matplotlib 0.98.3
which is a very outdated version (in fact, the documentation for it is no longer available).
Following my hunch, I downloaded the old source from here , the new source from here , and compared them.
It turns out that matplotlib 0.98.3
it only has links to axespad
, and matplotlib 1.4.2
has links only to borderaxespad
. The code they are in is almost exactly the same. It looks like at some point they added border functionality in legend
and decided to rename the argument accordingly.
source to share