def area_plot_table(table, **kwargs):
    """
    Plot a tabular DataFrame with an index and multiple columns representing
    categories using a Bokeh area chart.

    In addition to the keyword parameters accepted by bokeh.charts.Area, this
    function accepts the following additional keyword arguments:

    number_of_categories: integer
        The number of categories ranked by total value to use.
    xaxis_formatter: TickFormatter
        The formatter to use for x axis values.
    yaxis_formatter: TickFormatter
        The formatter to use for y axis values.
    x_range: Range1d
        A range to use for the X-axis.
    y_range: Range1d
        A range to use for the Y-axis.
    """
    if kwargs.has_key('number_of_categories'):
        acreage_table = analysis.select_top_n_columns(
            table, kwargs['number_of_categories'])
    else:
        acreage_table = table
    acre_plot = Area(
        acreage_table.reset_index(),
        x='year',
        y=map(str, acreage_table.columns),
        stack=True,
        **_remove_custom_keys(kwargs)
    )
    if kwargs.has_key('x_range'):
        acre_plot.xrange = kwargs['x_range']
    else:
        acre_plot.x_range = Range1d(acreage_table.index.min(), acreage_table.index.max())
    if kwargs.has_key('y_range'):
        acre_plot.y_range = kwargs['y_range']
    else:
        acre_plot.y_range = Range1d(0, acreage_table.max().sum())
    if kwargs.has_key('xaxis_formatter'):
        acre_plot._xaxis.formatter = kwargs['xaxis_formatter']
    if kwargs.has_key('yaxis_formatter'):
        acre_plot._yaxis.formatter = kwargs['yaxis_formatter']
    return acre_plot
示例#2
0
def area_plot_table(table, **kwargs):
    """
    Plot a tabular DataFrame with an index and multiple columns representing
    categories using a Bokeh area chart.

    In addition to the keyword parameters accepted by bokeh.charts.Area, this
    function accepts the following additional keyword arguments:

    number_of_categories: integer
        The number of categories ranked by total value to use.
    xaxis_formatter: TickFormatter
        The formatter to use for x axis values.
    yaxis_formatter: TickFormatter
        The formatter to use for y axis values.
    x_range: Range1d
        A range to use for the X-axis.
    y_range: Range1d
        A range to use for the Y-axis.
    """
    if kwargs.has_key('number_of_categories'):
        acreage_table = analysis.select_top_n_columns(
            table, kwargs['number_of_categories'])
    else:
        acreage_table = table
    acre_plot = Area(acreage_table.reset_index(),
                     x='year',
                     y=map(str, acreage_table.columns),
                     stack=True,
                     **_remove_custom_keys(kwargs))
    if kwargs.has_key('x_range'):
        acre_plot.xrange = kwargs['x_range']
    else:
        acre_plot.x_range = Range1d(acreage_table.index.min(),
                                    acreage_table.index.max())
    if kwargs.has_key('y_range'):
        acre_plot.y_range = kwargs['y_range']
    else:
        acre_plot.y_range = Range1d(0, acreage_table.max().sum())
    if kwargs.has_key('xaxis_formatter'):
        acre_plot._xaxis.formatter = kwargs['xaxis_formatter']
    if kwargs.has_key('yaxis_formatter'):
        acre_plot._yaxis.formatter = kwargs['yaxis_formatter']
    return acre_plot
示例#3
0
#area chart
areadata = dict(
    surprise=surpriseArray,
    like=likeArray,
    excite=exciteArray,
    disappoint=disappointArray,
    angry=angryArray,
    hate=hateArray
)

area = Area(areadata, title="情感走势图", legend="top_left",
             stack=True, xlabel='时间', ylabel='百分比', plot_width=730, plot_height=300, responsive=True, toolbar_location="below",
           toolbar_sticky=False,tools = ["wheel_zoom","box_zoom","reset","save"])
area.toolbar.logo = None
area.x_range = Range1d(0, 152)
area.y_range = Range1d(0, 1)

#scatter chart

scatterhover = HoverTool(
        tooltips="""
        <div>
            <div>
                <span style="font-size: 15px;">极性 @polarity</span>
            </div>
            <div>
                <span style="font-size: 15px;">浓度 @magnitude</span>
            </div>
            <div>
                <span style="font-size: 12px;">@review</span>