def draw(self, fig): """ Draw windrose plot of current data on figure """ try: axes = WindroseAxes(fig, rect=[0.1, 0.1, 0.8, 0.8]) fig.add_axes(axes) axes.bar(self.direction, self.windspeed, normed=True) axes.set_title("Windrose (by % in 6 bins)") legend = axes.legend(borderaxespad=-0.10, fontsize=8, bbox_to_anchor=(-0.2, 0)) legend_title = "Wind Speed" try: #Try adding a unit to the legend title units = self.configmanager.get_units() # Get unit strings from config legend_title = legend_title + " " + units["Wind Speed"].strip() except (KeyError, ValueError): pass # If no units exists, or the config isn't valid, just use title without units legend.set_title(legend_title, prop={"size":8}) except: raise
def wind_rose(station, AWS_var, model_var): fig = plt.figure(figsize = (16,8)) rect = [0.05, 0.1, 0.45, 0.6] wa = WindroseAxes(fig, rect) fig.add_axes(wa) # define data limits max_mod = max(np.mean(vars_yr['FF_10m'][:,lat_index14-1:lat_index14+1, lon_index14-1:lon_index14+1].data, axis = (1,2))) max_obs = max(AWS_var['FF']) wa.set_title('Observed', fontsize = 28, color = 'dimgrey', pad = 50) wa.axes.spines['polar'].set_visible(False) wa.tick_params(axis='both', which='both', labelsize=24, tick1On=False, tick2On=False, labelcolor='dimgrey', pad=10) wa.bar(AWS_var['WD'], AWS_var['FF'], bins = np.arange(0, max(max_mod, max_obs),4), cmap = plt.get_cmap('viridis'), normed = True,opening=0.8, edgecolor='white') wa.set_yticklabels([]) rect = [0.55, 0.1, 0.45, 0.6] wa = WindroseAxes(fig, rect) fig.add_axes(wa) wa.set_title('Modelled', fontsize=28, color='dimgrey', pad = 50) wa.bar(np.mean(vars_yr['WD'][:,lat_index14-1:lat_index14+1, lon_index14-1:lon_index14+1].data, axis = (1,2)), np.mean(vars_yr['FF_10m'][:,lat_index14-1:lat_index14+1, lon_index14-1:lon_index14+1].data, axis = (1,2)), bins = np.arange(0, max(max_mod, max_obs),4), cmap = plt.get_cmap('viridis'), normed = True, opening=0.8, edgecolor='white') lgd = wa.set_legend( bbox_to_anchor=(-0.5, 0.9)) frame = lgd.get_frame() frame.set_facecolor('white') for ln in lgd.get_texts(): plt.setp(ln, color='dimgrey', fontsize = 18) lgd.get_frame().set_linewidth(0.0) wa.axes.spines['polar'].set_visible(False) wa.set_yticklabels([]) wa.tick_params(axis='both', which='both', labelsize=24, tick1On=False, tick2On=False, labelcolor='dimgrey', pad=10) plt.savefig('/users/ellgil82/figures/Hindcast/validation/wind_rose_' + station + '_' + year + '.png') plt.savefig('/users/ellgil82/figures/Hindcast/validation/wind_rose_' + station + '_' + year + '.eps') plt.show()
def all_sta_wind_rose(): fig = plt.figure(figsize=(16, 16)) rect = [[0.05, 0.55, 0.35, 0.35], [0.55, 0.55, 0.35, 0.35], [0.05, 0.05, 0.35, 0.35], [0.55, 0.05,0.35, 0.35]] plot = 0 for station in station_dict.keys(): wa = WindroseAxes(fig, rect[plot]) fig.add_axes(wa) ANN, DJF, MAM, JJA, SON = load_AWS(station) # define data limits max_mod = max(ANN['FF_10m']) wa.set_title(station_dict[station], fontsize=28, color='dimgrey', pad=50) wa.axes.spines['polar'].set_visible(False) wa.tick_params(axis='both', which='both', labelsize=20, tick1On=False, tick2On=False, labelcolor='dimgrey', pad=10) wa.bar(ANN['WD'], ANN['FF_10m'], bins=np.arange(0, 20, 4), cmap=plt.get_cmap('viridis'), normed=True, opening=0.8, edgecolor='white') wa.set_yticks([5,10,15]) wa.set_yticklabels([ '', '10%', '15%']) plot = plot + 1 lgd = wa.set_legend(bbox_to_anchor=(-0.45, 1.)) frame = lgd.get_frame() frame.set_facecolor('white') for ln in lgd.get_texts(): plt.setp(ln, color='dimgrey', fontsize=24) lgd.get_frame().set_linewidth(0.0) if host == 'bsl': plt.savefig('/users/ellgil82/figures/Hindcast/Validation/wind_rose_all_stations_all_years.png') plt.savefig('/users/ellgil82/figures/Hindcast/Validation/wind_rose_all_stations_all_years.eps') elif host == 'jasmin': plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/wind_rose_all_stations_all_years.png') plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/wind_rose_all_stations_all_years.eps') plt.show()
def plot_roses(filename, vdir, mag, nsector=16, bins=10, title=None, legtitle=None, dpi=150, figsize=(10, 10), tfont=17, lfont=14): """ Plots the rose chart from wind data and saves it to png file. """ fig = plt.figure(figsize=figsize) # [left, bottom, width, height] as a fraction of total figure size right_rectangle = [0.05, 0.05, 0.85, 0.8] ax = WindroseAxes(fig, right_rectangle) fig.add_axes(ax) # ax.bar(wind['dir'], wind['sp'], normed=True, opening=0.9, edgecolor='white', bins=np.logspace(-1,1.3, 10), nsector=16) # ax.bar(wind['dir'], wind['sp'], normed=True, opening=0.9, edgecolor='white', bins=np.linspace(0,max(wind['sp']), 10), nsector=16) ax.bar(vdir, mag, normed=True, opening=0.9, edgecolor='white', bins=bins, nsector=nsector) if title: ax.set_title("{}".format(title), position=(0.5, 1.1), fontsize=tfont) cfont = max([8, lfont - 2]) ax.tick_params(axis='both', which='major', labelsize=cfont) ax.set_legend() if legtitle: ax.legend(title='{}'.format(legtitle), loc=(0.0, 0.0)) #used to pretty up the printing around of wind occurent frequencies tictic = ax.get_yticks() ax.set_yticks(np.arange(0, tictic[-1], tictic[-1] / len(tictic))) ax.yaxis.set_major_formatter(tkr.FormatStrFormatter('%2.0f')) if isinstance(filename, list): for item in filename: fig.savefig(item, dpi=dpi) else: fig.savefig(filename, dpi=dpi) plt.close() return 0
ax1 = fig.add_axes(left_rectangle) # creates the axes of specified dimensions mto[wsp].hist(bins=100) ax1.set_xscale("log") ax1.set_xlabel("wind speed (m/s)") right_rectangle = [0.5, 0.1, 0.5, 0.75] # [left, bottom, width, height] ax = WindroseAxes(fig, right_rectangle) fig.add_axes(ax) ax.bar(mto[wdir], mto[wsp], normed=True, opening=0.8, edgecolor='white', bins=np.logspace(-1, 1, 10)) ax.set_title("annual", position=(0.5, 1.1)) ax.set_legend() ax.legend(title="wind speed (m/s)", loc=(1.1, 0)) ###################################################################### # The numbers around the radar plot indicate frequencies for the given # direction. They look quite ugly, and would benefit from some formatting. # which is not super trivial: # from windrose import WindroseAxes fig = plt.figure(figsize=(10, 5)) left_rectangle = [