Example #1
0
 def __init__(self, *args, **kwargs):
     """
     See Axes base class for args and kwargs documentation
     """
     
     #Uncomment to have the possibility to change the resolution directly 
     #when the instance is created
     #self.RESOLUTION = kwargs.pop('resolution', 100)
     PolarAxes.__init__(self, *args, **kwargs)
     self.set_aspect('equal', adjustable='box', anchor='C')
     self.radii_angle = 67.5
     self.cla()
Example #2
0
    def __init__(self, *args, **kwargs):
        """
        See Axes base class for args and kwargs documentation
        """

        #Uncomment to have the possibility to change the resolution directly
        #when the instance is created
        #self.RESOLUTION = kwargs.pop('resolution', 100)
        PolarAxes.__init__(self, *args, **kwargs)
        self.set_aspect('equal', adjustable='box', anchor='C')
        self.radii_angle = 67.5
        self.cla()
Example #3
0
    def cla(self):
        """
        Clear the current axes
        """
        PolarAxes.cla(self)

        self.theta_angles = np.arange(0, 360, 45)
        self.theta_labels = ['E', 'N-E', 'N', 'N-W', 'W', 'S-W', 'S', 'S-E']
        self.set_thetagrids(angles=self.theta_angles, labels=self.theta_labels)

        self._info = {'dir': list(), 'bins': list(), 'table': list()}

        self.patches_list = list()
Example #4
0
    def __init__(self, *args, **kwargs):
        """
        See Axes base class for args and kwargs documentation
        """

        # Uncomment to have the possibility to change the resolution directly
        # when the instance is created
        # self.RESOLUTION = kwargs.pop('resolution', 100)
        self.rmax = kwargs.pop("rmax", None)
        self.theta_labels = kwargs.pop("theta_labels", ["E", "N-E", "N", "N-W", "W", "S-W", "S", "S-E"])
        PolarAxes.__init__(self, *args, **kwargs)
        self.set_aspect("equal", adjustable="box", anchor="C")
        self.radii_angle = 67.5
        self.cla()
Example #5
0
    def cla(self):
        """
        Clear the current axes
        """
        PolarAxes.cla(self)

        self.theta_angles = np.arange(0, 360, 45)
        self.set_thetagrids(angles=self.theta_angles, labels=self.theta_labels)

        self._info = {"dir": list(), "bins": list(), "table": list()}

        self.patches_list = list()

        self.calm_count = None
Example #6
0
    def cla(self):
        """
        Clear the current axes
        """
        PolarAxes.cla(self)

        self.theta_angles = np.arange(0, 360, 45)
        self.theta_labels = ['E', 'N-E', 'N', 'N-W', 'W', 'S-W', 'S', 'S-E']
        self.set_thetagrids(angles=self.theta_angles, labels=self.theta_labels)

        self._info = {'dir' : list(),
                      'bins' : list(),
                      'table' : list()}

        self.patches_list = list()
Example #7
0
            def _gen_axes_spines(self):

                if frame == 'circle':
                    return PolarAxes._gen_axes_spines(self)

                # The following is a hack to get the spines (i.e. the axes frame)

                # to draw correctly for a polygon frame.

                # spine_type must be 'left', 'right', 'top', 'bottom', or `circle`.

                spine_type = 'circle'

                verts = unit_poly_verts(theta + np.pi / 2)

                # close off polygon by repeating first vertex

                verts.append(verts[0])

                path = Path(verts)

                spine = Spine(self, spine_type, path)

                spine.set_transform(self.transAxes)

                return {'polar': spine}
Example #8
0
 def __init__(self, **kwargs):
     """Construct a WindrosePlot."""
     self.fig = plt.figure(figsize=(8, 8),
                           dpi=100,
                           facecolor="w",
                           edgecolor="w")
     rect = [0.12, 0.12, 0.76, 0.76]
     self.ax = PolarAxes(self.fig,
                         rect,
                         theta_offset=np.pi / 2.0,
                         theta_direction=-1)
     self.ax.set_xticks(np.arange(0, 2.0 * np.pi - 0.01, 2.0 * np.pi / 8.0))
     self.ax.set_xticklabels(LABELS)
     self.fig.add_axes(self.ax)
     self.table = None
     self.calm_percent = None
     self.rmax = kwargs.get("rmax")
 def _gen_axes_spines(self):
     if frame == "circle": return PolarAxes._gen_axes_spines(self)
     spine_type, verts = "circle", unit_poly_verts(theta)
     verts.append(verts[0])
     path = Path(verts)
     spine = Spine(self, spine_type, path)
     spine.set_transform(self.transAxes)
     return {'polar': spine}
Example #10
0
 def _gen_axes_spines(self):
     if self.radar_patch_type == 'circle':
         return PolarAxes._gen_axes_spines(self)
     spine_type = 'circle'
     verts = unit_poly_verts(self.radar_theta)
     verts.append(verts[0])
     path = Path(verts)
     spine = Spine(self, self.radar_spine_type, path)
     spine.set_transform(self.transAxes)
     return {'polar': spine}
        def _gen_axes_spines(self):
            if frame == 'circle':
                return PolarAxes._gen_axes_spines(self)

            spine_type = 'circle'
            verts = unit_poly_verts(theta)
            verts.append(verts[0])
            path = Path(verts)

            spine = Spine(self, spine_type, path)
            spine.set_transform(self.transAxes)
            return {'polar': spine}
Example #12
0
    def cla(self):
        """
        Clear the current axes
        """
        PolarAxes.cla(self)
        theta_delta = 30
        self.theta_angles = np.arange(0, 360, theta_delta)
        #        self.theta_labels = ['E', 'N-E', 'N', 'N-W', 'W',
        #                            'S-W', 'S', 'S-E']
        first_quad = range(90, -1, -theta_delta)
        quads = range(330, 89, -theta_delta)
        all_quads = first_quad + quads
        self.theta_labels = [str(a) for a in all_quads]
        self.set_thetagrids(angles=self.theta_angles,
                            labels=self.theta_labels)

        self._info = {'dir': list(),
                      'bins': list(),
                      'table': list()}

        self.patches_list = list()
Example #13
0
            def _gen_axes_spines(self):
                if frame == 'circle':
                    return PolarAxes._gen_axes_spines(self)

                spine_type = 'circle'
                verts = unit_poly_verts(theta)
                # close off polygon by repeating first vertex
                verts.append(verts[0])
                path = Path(verts)

                spine = Spine(self, spine_type, path)
                spine.set_transform(self.transAxes)
                return {'polar': spine}
Example #14
0
 def _gen_axes_spines(self):
     if self.radar_patch_type == 'circle':
         return PolarAxes._gen_axes_spines(self)
     # The following is a hack to get the spines (i.e. the axes frame)
     # to draw correctly for a polygon frame.
     spine_type = 'circle'
     verts = unit_poly_verts(self.radar_theta)
     # close off polygon by repeating first vertex
     verts.append(verts[0])
     path = Path(verts)
     spine = Spine(self, self.radar_spine_type, path)
     spine.set_transform(self.transAxes)
     return {'polar': spine}
Example #15
0
 def _gen_axes_spines(self):
     if self.radar_patch_type == 'circle':
         return PolarAxes._gen_axes_spines(self)
     # The following is a hack to get the spines (i.e. the axes frame)
     # to draw correctly for a polygon frame.
     spine_type = 'circle'
     verts = unit_poly_verts(self.radar_theta)
     # close off polygon by repeating first vertex
     verts.append(verts[0])
     path = Path(verts)
     spine = Spine(self, self.radar_spine_type, path)
     spine.set_transform(self.transAxes)
     return {'polar': spine}
 def _gen_axes_spines(self):
     if frame == 'circle':
         return PolarAxes._gen_axes_spines(self)
     # The following is a hack to get the spines (i.e. the axes frame)
     # to draw correctly for a polygon frame.
     # spine_type must be 'left', 'right', 'top', 'bottom', or `circle`.
     spine_type = 'circle'
     verts = unit_poly_verts(theta)
     # close off polygon by repeating first vertex
     verts.append(verts[0])
     path = Path(verts)
     spine = Spine(self, spine_type, path)
     spine.set_transform(self.transAxes)
     return {'polar': spine}
Example #17
0
def plainify_rose_plot(fig: Figure, ax: PolarAxes):
    """
    Make plain version of rose plots with only bars.
    """
    ax.set_title("")
    for txt in ax.texts:
        txt.set_visible(False)
    ax.set_rgrids([]), ax.set_thetagrids([]), ax.set_axis_off()
    fig.patch.set_alpha(1)
    ax.patch.set_alpha(1)
        def _gen_axes_spines(self):
            if frame == 'circle':
                return PolarAxes._gen_axes_spines(self)
            # The following is a hack to get the spines (i.e. the axes frame)
            # to draw correctly for a polygon frame.

            # spine_type haruslah 'left', 'right', 'top', 'bottom', or `circle`.
            spine_type = 'circle'
            verts = unit_poly_verts(theta)
            # menghentikan sementara polygon dengan mengulangi vertex awal
            verts.append(verts[0])
            path = Path(verts)

            spine = Spine(self, spine_type, path)
            spine.set_transform(self.transAxes)
            return {'polar': spine}
Example #19
0
class WindrosePlot:
    """A plot that has a single windrose on it."""
    def __init__(self, **kwargs):
        """Construct a WindrosePlot."""
        self.fig = plt.figure(figsize=(8, 8),
                              dpi=100,
                              facecolor="w",
                              edgecolor="w")
        rect = [0.12, 0.12, 0.76, 0.76]
        self.ax = PolarAxes(self.fig,
                            rect,
                            theta_offset=np.pi / 2.0,
                            theta_direction=-1)
        self.ax.set_xticks(np.arange(0, 2.0 * np.pi - 0.01, 2.0 * np.pi / 8.0))
        self.ax.set_xticklabels(LABELS)
        self.fig.add_axes(self.ax)
        self.table = None
        self.calm_percent = None
        self.rmax = kwargs.get("rmax")

    def barplot(self, direction, speed, bins, nsector):
        """Do the bar plotting work."""
        # compute histogram
        self.calm_percent, dir_centers, self.table = histogram(
            speed, direction, bins, nsector)
        theta = dir_centers.to(units("radian")).m
        base = np.zeros(dir_centers.m.shape[0])
        width = (theta[1] - theta[0]) * 0.8
        for col in range(self.table.shape[1]):
            if col < (bins.m.shape[0] - 1):
                label = "%s - %s" % (bins.m[col], bins.m[col + 1])
            else:
                label = "%s+" % (bins.m[col], )
            self.ax.bar(
                theta,
                self.table[:, col].m,
                bottom=base,
                width=width,
                align="center",
                label=label,
            )
            base += self.table[:, col].m
        if self.rmax is not None:
            self.ax.set_ylim(0, self.rmax)
        # Place axis label in least congested spot
        self.ax.set_rlabel_position(dir_centers.m[np.argmin(base)])
        # Append a % on the label
        self.ax.yaxis.set_major_formatter(FormatStrFormatter("%.1f%%"))
        # Draw Legend
        self.ax.legend(
            bbox_to_anchor=(0.01, -0.15, 0.98, 0.09),
            loc="center",
            ncol=6,
            fontsize=10,
            mode=None,
            columnspacing=0.9,
            handletextpad=0.75,
            # Ugly hack here due to aliasing in pint for mph
            title="Wind Speed [%s]" %
            ("mph" if bins.units == units("mph") else bins.units, ),
        )

    def plot_calm(self):
        """Clear out the center and plot the calm value."""
        maxval = np.max(np.sum(self.table, axis=1))
        # Clear out the center for plotting the calm percentage
        self.ax.set_rorigin(0 - maxval.m * 0.2)
        # Place Calm Percent in the middle
        self.ax.text(
            0.5,
            0.5,
            "Calm\n%.1f%%" % (self.calm_percent.m, ),
            ha="center",
            va="center",
            transform=self.ax.transAxes,
        )

    def draw_logo(self):
        """Brand the plot."""
        datadir = os.sep.join([os.path.dirname(__file__), "..", "data"])
        im = mpimage.imread("%s/%s" % (datadir, "logo.png"))
        plt.figimage(im, 10, 735)

    def draw_arrows(self):
        """Place arrows on the border."""
        rmin, rmax = self.ax.get_ylim()
        for x in self.ax.get_xticks():
            # https://github.com/matplotlib/matplotlib/issues/5344
            self.ax.annotate(
                "",
                xy=(x + 0.001, rmax - (rmax - rmin) * 0.12),
                xytext=(x + 0.001, rmax + (rmax - rmin) * 0.02),
                arrowprops=dict(
                    facecolor="None",
                    edgecolor="k",
                    alpha=0.8,
                    shrink=0.09,
                    zorder=10,
                ),
                ha="center",
                va="center",
                zorder=Z_OVERLAY2,
            )
Example #20
0
	def _gen_axes_spines(self):
		"""Overwrite method"""
		return PolarAxes._gen_axes_spines(self)
Example #21
0
def Taylor_diag(series, smax=1.5):
    """ Taylor Diagram : obs is reference data sample
        in a full diagram (0 --> npi)
        --------------------------------------------------------------------------
        Input: series     - dict with all time series (lists) to analyze  
               series[0]  - is the observation, the reference by default.
    """
    corr,std ={},{}
    for i in series.keys():
        corr[i] = ma.corrcoef(series[0],series[i])[1,0]
        std[i] = ma.std(series[i])/ma.std(series[0])
    
    ref = 1# ma.std(series[0])
    
    # radial grid
    # rlocs = np.concatenate((np.arange(0,1,0.2),[0.95,0.99]))  # correlation coefficient tick marks
    rlocs = [0, .3, .6, .8, .95, .99]
    str_rlocs = np.concatenate((np.arange(0,1,0.2),[0.95,0.99],np.arange(0,10,0.2),[0.95,0.99]))
    tlocs = np.arccos(rlocs)        # Conversion to polar angles
    gl1 = GF.FixedLocator(tlocs)    # Positions
    tf1 = GF.DictFormatter(dict(zip(tlocs, map("{:.2f}".format, rlocs))))

    # circumferencial grid
    str_locs2 = tlocs2 =  np.arange(0, 2, 0.2)
    g22 = GF.FixedLocator(tlocs2)  
    tf2 = GF.DictFormatter(dict(zip(tlocs2, map("{:.1f}".format, str_locs2))))

    tr = PolarAxes.PolarTransform()
    
    smin = 0

    ghelper = FA.GridHelperCurveLinear(tr,
                                       extremes=(0, np.pi/2, # 1st quadrant
                                                 smin,smax),
                                       grid_locator1=gl1,
                                       tick_formatter1=tf1,
                                       tick_formatter2=tf2,
                                       )
    fig = plt.figure(figsize=(7, 5), dpi=100)
    ax = FA.FloatingSubplot(fig, 111, grid_helper=ghelper)

    fig.add_subplot(ax)
    ax.axis["top"].set_axis_direction("bottom") 
    ax.axis["top"].toggle(ticklabels=True, label=True)
    ax.axis["top"].major_ticklabels.set_axis_direction("top")
    ax.axis["top"].label.set_axis_direction("top")
    ax.axis["top"].label.set_text("Correlation Coefficient")

    ax.axis["left"].set_axis_direction("bottom") 
    ax.axis["left"].label.set_text("Standard Deviation")

    ax.axis["right"].set_axis_direction("top") 
    ax.axis["right"].toggle(ticklabels=True, label=True)
    ax.axis["right"].set_visible(True)
    ax.axis["right"].major_ticklabels.set_axis_direction("bottom")
    #ax.axis["right"].label.set_text("Standard Deviation")

    ax.axis["bottom"].set_visible(False) 

    ax.grid(True)

    ax = ax.get_aux_axes(tr)

    # radial RMS error lines from observed.
    t = np.linspace(0, np.pi)
    r = np.zeros_like(t) + ref
    ax.plot(t, r, 'k--', label='_')

    rs,ts = np.meshgrid(np.linspace(smin,smax),
                        np.linspace(0,np.pi))
    
    rms = np.sqrt(ref**2 + rs**2 - 2*ref*rs*np.cos(ts))
    # CS = ax.contour(ts, rs, rms, colors='k', alpha=0.6, linewidths=1)
    # plt.clabel(CS, inline=1, fontsize=10)
    
    # plot observed point
    ax.plot(np.arccos(0.9999),ref,'k',marker='*',ls='', ms=10, label='Observed')

    # plot modelled points
    aux = [k for k in series.keys() if k != 0]
    
    for i in aux:
        ax.scatter(np.arccos(corr[i]), std[i], marker='o', label=i, zorder=5, s=50)
        # ax.text(np.arccos(corr[i]), std[i], i)
    
    plt.legend(bbox_to_anchor=(1.7, 1),prop=dict(size='large'),loc='best', fontsize=8)
    
    return fig, ax