一个简单的实现:
import matplotlib.pyplot as plt
def plot_velocity_duration_curve(sites):
for i, site in enumerate(sites, 1):
windspeed = sorted(site, reverse=True)
fractions = [j/len(site) for j in range(1, len(site)+1)]
plt.plot(fractions, windspeed, '-o', label=f'site {i}')
plt.legend(loc='upper right')
plt.title('Velocity duration curves')
plt.xlabel('Fraction of time')
plt.ylabel('Wind speed (m/s)')
plt.xticks([i/10 for i in range(1,11)])
plt.grid()
plt.show()
site1 = [2, 3, 3, 4, 4, 4, 4, 6, 5, 5]
site2 = [2, 2, 6, 3, 7, 6, 1, 5, 6, 2]
plot_velocity_duration_curve([site1, site2])
以及使用numpy 更高效的实现:
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
def plot_velocity_duration_curve(sites):
fractions = np.arange(1.,len(sites)+1) /len(sites)
windspeed = np.sort(sites, axis=0)[::-1]
lines = plt.plot(fractions, windspeed, '-o', label=f'site')
plt.legend(lines, [f"site {i}" for i in range(1, len(lines)+1)])
plt.title('Velocity duration curves')
plt.xlabel('Fraction of time')
plt.ylabel('Wind speed (m/s)')
plt.xticks(np.arange(0, 1.1, step=0.1))
plt.grid()
plt.show()
site1 = np.random.rayleigh(10,20)
site2 = np.random.rayleigh(9,20)
site3 = np.random.normal(10,5,20)
sites = np.c_[site1, site2, site3]
plot_velocity_duration_curve(sites)
请参阅 this answer 了解更广泛的实施。