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
示例#2
0
    def rose_diagram(self, direction, norm):

        """
        Plot rose diagram

        Inputs:
          - direction = 1D array
          - norm = 1D array
        """
        #Convertion
        #TR: not quite sure here, seems to change from location to location
        #    express principal axis in compass
        direction = np.mod(90.0 - direction, 360.0)

        #Create new figure
        self._def_fig()  
        rect = [0.1, 0.1, 0.8, 0.8]
        ax = WindroseAxes(self._fig, rect)#, axisbg='w')
        self._fig.add_axes(ax)
        #Rose
        ax.bar(direction, norm , normed=True, opening=0.8, edgecolor='white')
        #adjust legend
        l = ax.legend(shadow=True, bbox_to_anchor=[-0.1, 0], loc='lower left')
        plt.setp(l.get_texts(), fontsize=10)
        plt.xlabel('Rose diagram in % of occurrences - Colormap of norms')
        self._plt.show() 
示例#3
0
    def rose_diagram(self, direction, norm):

        """
        Plot rose diagram

        Inputs:
        ------
          - direction = 1D array
          - norm = 1D array
        """
        #Convertion
        #TR: not quite sure here, seems to change from location to location
        #    express principal axis in compass
        direction = np.mod(90.0 - direction, 360.0)

        #Create new figure
        fig = plt.figure(figsize=(18,10))
        plt.rc('font',size='22')
        rect = [0.1, 0.1, 0.8, 0.8]
        ax = WindroseAxes(fig, rect)#, axisbg='w')
        fig.add_axes(ax)
        #Rose
        ax.bar(direction, norm , normed=True, opening=0.8, edgecolor='white')
        #adjust legend
        l = ax.legend(shadow=True, bbox_to_anchor=[-0.1, 0], loc='lower left')
        plt.setp(l.get_texts(), fontsize=10)
        plt.xlabel('Rose diagram in % of occurrences - Colormap of norms')
        plt.show() 
示例#4
0
    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
示例#5
0
    def wros(self, ws, wd, maxi=10, dev=None, date=None, base=None):
        '''Plot a wind rose given an array of wind speed and wind direction'''

        fig = plt.figure(figsize=(30, 30),
                         dpi=150,
                         facecolor='w',
                         edgecolor='w')
        rect = [0.1, 0.1, 0.8, 0.8]
        ax = WindroseAxes(fig, rect, axisbg='w')
        fig.add_axes(ax, fontsize=12)
        try:
            ax.bar(wd,
                   ws,
                   normed=True,
                   opening=1,
                   edgecolor='white',
                   bins=[0, 2, 6, 12, 20, 29, 39, 50])
            ax.set_rmax(12)
            ax.set_radii_angle()
            l = ax.legend(loc=(1, 0))
            if self.periods == None:
                if base != None and date != None:
                    title = 'Wind rose at ' + str(
                        self.height) + 'm and at ' + str(
                            self.selected_cell[0]) + ' in ' + str(
                                date) + ' during the ' + str(
                                    base) + ' by ' + str(dev)
                elif base != None:
                    title = 'Wind rose at ' + str(
                        self.height) + 'm and at ' + str(
                            self.selected_cell[0]) + ' during the ' + str(
                                base) + ' by ' + str(dev)
                elif date != None:
                    title = 'Wind rose at ' + str(
                        self.height) + 'm and at ' + str(
                            self.selected_cell[0]) + ' in ' + str(
                                date) + ' by ' + str(dev)
                else:
                    title = 'Wind rose at ' + str(
                        self.height) + 'm and at ' + str(
                            self.selected_cell[0]) + ' by ' + str(dev)
            else:
                title = 'Wind statistics at ' + str(
                    self.height) + 'm and at ' + str(
                        self.selected_cell[0]) + str(
                            self.periods) + ' by ' + str(dev)
            plt.setp(l.get_texts(), fontsize=12)
            plt.title(title, fontsize=12, y=1.07)
            plt.show()
        except ValueError:
            print 'No windrose for ' + str(dev)
示例#6
0
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 = [
    0, 0.1, 0.4, 0.75
]  # [left, bottom, width, height] as a fraction of total figure size
ax1 = fig.add_axes(left_rectangle)  # creates the axes of specified dimensions