Reputation: 21
I am trying to analyze windroses in Python. How can I make all the plots with the same scale? I have a CSV file with wind speed and direction.
Here is my code:
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 pandas as pd
MON=pd.read_csv(r'data.csv')
ws = MON["Ws"].values
wd = MON["Wd"].values
ax = WindroseAxes.from_ax()
ax.bar(wd, ws, normed=True, opening=0.8, edgecolor='white')
ax.set_title('plot2')
ax.set_legend()
Tthe two plots are showing two different legends. I want one fixed legend for two plots.
First plot:
sp.png
Second plot:
Upvotes: 2
Views: 510
Reputation: 80534
In order to have a consistent legend for multiple windrose plots, you can manually add a bins=
parameter to ax.bar
of the windrose. By default, there are 6 bin edges between the minimum and maximum of the given data.
Here is an example where the data for the first plot has a range between 0 and 6, while the data for the second plot ranges between 0 and 9:
import matplotlib.pyplot as plt
import windrose
import numpy as np
ws0 = np.random.random(500) * 6
ws1 = np.random.random(500) * 9
wd = np.random.random(500) * 360
bins = [0, 2, 4, 6, 8]
fig, (wa0, wa1) = plt.subplots(ncols=2, figsize=(9, 5),
subplot_kw={'projection': 'windrose'})
wa0.bar(wd, ws0, normed=True, opening=0.8, edgecolor='white', bins=bins)
wa1.bar(wd, ws1, normed=True, opening=0.8, edgecolor='white', bins=bins)
wa0.legend()
wa1.legend()
plt.tight_layout()
plt.show()
Upvotes: 2