'Create a word_cloud from words and frequencies.
Parameters
frequencies : dict from string to float
A contains words and associated frequency.
max_font_size : int
Use this font-size instead of self.max_font_size
Returns
self'

def generate_from_frequencies(self, frequencies, max_font_size=None):

    frequencies = sorted(frequencies.items(), key=item1, reverse=True)
    if (len(frequencies) <= 0):
        raise ValueError(('We    need    at    least    1    word    to    plot    a    word    cloud,    got    %d.' % len(frequencies)))
    frequencies = frequencies[:self.max_words]
    max_frequency = float(frequencies[0][1])
    frequencies = [(word, (freq / max_frequency)) for (word, freq) in frequencies]
    if (self.random_state is not None):
        random_state = self.random_state
    else:
        random_state = Random()
    if (self.mask is not None):
        mask = self.mask
        width = mask.shape[1]
        height = mask.shape[0]
        if (mask.dtype.kind == 'f'):
            warnings.warn('mask    image    should    be    unsigned    byte    between    0    and    255.    Got    a    float    array')
        if (mask.ndim == 2):
            boolean_mask = (mask == 255)
        elif (mask.ndim == 3):
            boolean_mask = np.all((mask[:, :, :3] == 255), axis=(-1))
        else:
            raise ValueError(('Got    mask    of    invalid    shape:    %s' % str(mask.shape)))
    else:
        boolean_mask = None
        (height, width) = (self.height, self.width)
    occupancy = IntegralOccupancyMap(height, width, boolean_mask)
    img_grey = Image.new('L', (width, height))
    draw = ImageDraw.Draw(img_grey)
    img_array = np.asarray(img_grey)
    (font_sizes, positions, orientations, colors) = ([], [], [], [])
    last_freq = 1.0
    if (max_font_size is None):
        max_font_size = self.max_font_size
    if (max_font_size is None):
        if (len(frequencies) == 1):
            font_size = self.height
        else:
            self.generate_from_frequencies(dict(frequencies[:2]), max_font_size=self.height)
            sizes = [x[1] for x in self.layout_]
            font_size = int((((2 * sizes[0]) * sizes[1]) / (sizes[0] + sizes[1])))
    else:
        font_size = max_font_size
    self.words_ = dict(frequencies)
    for (word, freq) in frequencies:
        rs = self.relative_scaling
        if (rs != 0):
            font_size = int(round((((rs * (freq / float(last_freq))) + (1 - rs)) * font_size)))
        if (random_state.random() < self.prefer_horizontal):
            orientation = None
        else:
            orientation = Image.ROTATE_90
        tried_other_orientation = False
        while True:
            font = ImageFont.truetype(self.font_path, font_size)
            transposed_font = ImageFont.TransposedFont(font, orientation=orientation)
            box_size = draw.textsize(word, font=transposed_font)
            result = occupancy.sample_position((box_size[1] + self.margin), (box_size[0] + self.margin), random_state)
            if ((result is not None) or (font_size < self.min_font_size)):
                break
            if ((not tried_other_orientation) and (self.prefer_horizontal < 1)):
                orientation = (Image.ROTATE_90 if (orientation is None) else Image.ROTATE_90)
                tried_other_orientation = True
            else:
                font_size -= self.font_step
                orientation = None
        if (font_size < self.min_font_size):
            break
        (x, y) = (np.array(result) + (self.margin // 2))
        draw.text((y, x), word, fill='white', font=transposed_font)
        positions.append((x, y))
        orientations.append(orientation)
        font_sizes.append(font_size)
        colors.append(self.color_func(word, font_size=font_size, position=(x, y), orientation=orientation, random_state=random_state, font_path=self.font_path))
        if (self.mask is None):
            img_array = np.asarray(img_grey)
        else:
            img_array = (np.asarray(img_grey) + boolean_mask)
        occupancy.update(img_array, x, y)
        last_freq = freq
    self.layout_ = list(zip(frequencies, font_sizes, positions, orientations, colors))
    return self
