Beispiel #1
0
def plot_distribution(ax, cmap, probabilitydist, fig, time_from, reference_data=None):
    """
    Plot forecasted ProbabilityDistribution objects on a matplotlib axis

    :param ax: matplotlib axis
    :param cmap: matplotlib colormap name
    :param probabilitydist: list of ProbabilityDistribution objects
    :param fig: matplotlib figure
    :param time_from: starting time (on x axis) to begin the plots
    :param reference_data:
    :return:
    """
    from matplotlib.patches import Rectangle
    from matplotlib.collections import PatchCollection
    patches = []
    colors = []
    for ct, dt in enumerate(probabilitydist):
        disp = 0.0
        if reference_data is not None:
            disp = reference_data[time_from+ct]

        for y in dt.bins:
            s = Rectangle((time_from+ct, y+disp), 1, dt.resolution, fill=True, lw = 0)
            patches.append(s)
            colors.append(dt.density(y))
    scale = Transformations.Scale()
    colors = scale.apply(colors)
    pc = PatchCollection(patches=patches, match_original=True)
    pc.set_clim([0, 1])
    pc.set_cmap(cmap)
    pc.set_array(np.array(colors))
    ax.add_collection(pc)
    cb = fig.colorbar(pc, ax=ax)
    cb.set_label('Density')
Beispiel #2
0
def plot_distribution(ax,
                      cmap,
                      probabilitydist,
                      fig,
                      time_from,
                      reference_data=None):
    from matplotlib.patches import Rectangle
    from matplotlib.collections import PatchCollection
    patches = []
    colors = []
    for ct, dt in enumerate(probabilitydist):
        disp = 0.0
        if reference_data is not None:
            disp = reference_data[time_from + ct]

        for y in dt.bins:
            s = Rectangle((time_from + ct, y + disp),
                          1,
                          dt.resolution,
                          fill=True,
                          lw=0)
            patches.append(s)
            colors.append(dt.density(y))
    scale = Transformations.Scale()
    colors = scale.apply(colors)
    pc = PatchCollection(patches=patches, match_original=True)
    pc.set_clim([0, 1])
    pc.set_cmap(cmap)
    pc.set_array(np.array(colors))
    ax.add_collection(pc)
    cb = fig.colorbar(pc, ax=ax)
    cb.set_label('Density')
Beispiel #3
0
    def __init__(self, **kwargs):
        self.h = kwargs.get('h', .5)
        """Width parameter"""
        self.kernel = kwargs.get("kernel", "epanechnikov")
        """Kernel function"""
        self.data = kwargs.get("data", None)
        self.transf = Transformations.Scale(min=0, max=1)

        if self.data is not None:
            self.data = self.transf.apply(self.data)
Beispiel #4
0
 def __init__(self,h, kernel="epanechnikov"):
     self.h = h
     """Width parameter"""
     self.kernel = kernel
     """Kernel function"""
     self.transf = Transformations.Scale(min=0,max=1)
Beispiel #5
0
 def __init__(self, h, kernel="epanechnikov"):
     self.h = h
     self.kernel = kernel
     self.transf = Transformations.Scale(min=0, max=1)