def Chord(data, source=None, target=None, value=None, square_matrix=False, label=None, **kws): """ Create a chord chart using :class:`ChordBuilder <bokeh.charts.builders.chord_builder.ChordBuilder>` to render a chord graph from a variety of value forms. This chart displays the inter-relationships between data in a matrix. The data can be generated by the chart interface. Given a source Reference: `Chord diagram on Wikipedia <https://en.wikipedia.org/wiki/Chord_diagram>`_ Args: data (:ref:`userguide_charts_data_types`): the data source for the chart. source (list(str) or str, optional): Data source to use as origin of the connection to a destination. target (list(str) or str, optional): Data source to use as destination of a connection. value (list(num) or num, optional): The value the connection should have. square_matrix (bool, optional): If square matrix, avoid any calculations during the setup. label (list(str or num) optional): The labels to be put in the areas. Returns: :class:`Chart`: includes glyph renderers that generate the chord Examples: .. bokeh-plot:: :source-position: above import pandas as pd from bokeh.charts import output_file, Chord from bokeh.io import show from bokeh.sampledata.les_mis import data nodes = data['nodes'] links = data['links'] nodes_df = pd.DataFrame(nodes) links_df = pd.DataFrame(links) source_data = links_df.merge(nodes_df, how='left', left_on='source', right_index=True) source_data = source_data.merge(nodes_df, how='left', left_on='target', right_index=True) source_data = source_data[source_data["value"] > 5] chord_from_df = Chord(source_data, source="name_x", target="name_y", value="value") output_file('chord_from_df.html', mode="inline") show(chord_from_df) """ kws["origin"] = source kws["destination"] = target kws["value"] = value kws["square_matrix"] = square_matrix kws["label"] = label return create_and_build(ChordBuilder, data, **kws)
def Scatter(data=None, x=None, y=None, **kws): """ Create a scatter chart using :class:`ScatterBuilder <bokeh.charts.builders.scatter_builder.ScatterBuilder>` to render the geometry from values. Args: data (:ref:`userguide_charts_data_types`): table-like data x (str or list(str), optional): the column label to use for the x dimension y (str or list(str), optional): the column label to use for the y dimension In addition to the parameters specific to this chart, :ref:`userguide_charts_defaults` are also accepted as keyword parameters. Returns: :class:`Chart`: includes glyph renderers that generate the scatter points Examples: .. bokeh-plot:: :source-position: above from bokeh.sampledata.autompg import autompg as df from bokeh.charts import Scatter, output_file, show scatter = Scatter(df, x='mpg', y='hp', color='cyl', marker='origin', title="Auto MPG", xlabel="Miles Per Gallon", ylabel="Horsepower") output_file('scatter.html') show(scatter) """ kws['x'] = x kws['y'] = y return create_and_build(ScatterBuilder, data, **kws)
def Horizon(data=None, x=None, y=None, series=None, **kws): """ Create a scatter chart using :class:`ScatterBuilder <bokeh.charts.builders.scatter_builder.ScatterBuilder>` to render the geometry from values. Args: data (:ref:`userguide_charts_data_types`): table-like data x (str or list(str), optional): the column label to use for the x dimension y (str or list(str), optional): the column label to use for the y dimension In addition the the parameters specific to this chart, :ref:`userguide_charts_defaults` are also accepted as keyword parameters. Returns: :class:`Chart`: includes glyph renderers that generate the scatter points Examples: .. bokeh-plot:: :source-position: above from bokeh.sampledata.autompg import autompg as df from bokeh.charts import Scatter, output_file, show scatter = Scatter(df, x='mpg', y='hp', color='cyl', marker='origin', title="Auto MPG", xlabel="Miles Per Gallon", ylabel="Horsepower") output_file('scatter.html') show(scatter) """ kws['x'] = x kws['y'] = y kws['series'] = series tools = kws.get('tools', True) if tools == True: tools = "save,resize,reset" elif isinstance(tools, string_types): tools = tools.replace('pan', '') tools = tools.replace('wheel_zoom', '') tools = tools.replace('box_zoom', '') tools = tools.replace(',,', ',') kws['tools'] = tools chart = create_and_build(HorizonBuilder, data, **kws) # Hide numerical axis chart.left[0].visible = False # Add the series names to the y axis chart.extra_y_ranges = { "series": FactorRange(factors=chart._builders[0].series_names) } chart.add_layout(CategoricalAxis(y_range_name="series"), 'left') return chart
def Horizon(data=None, x=None, y=None, series=None, **kws): """ Create a scatter chart using :class:`ScatterBuilder <bokeh.charts.builders.scatter_builder.ScatterBuilder>` to render the geometry from values. Args: data (:ref:`userguide_charts_data_types`): table-like data x (str or list(str), optional): the column label to use for the x dimension y (str or list(str), optional): the column label to use for the y dimension In addition the the parameters specific to this chart, :ref:`userguide_charts_defaults` are also accepted as keyword parameters. Returns: :class:`Chart`: includes glyph renderers that generate the scatter points Examples: .. bokeh-plot:: :source-position: above from bokeh.sampledata.autompg import autompg as df from bokeh.charts import Scatter, output_file, show scatter = Scatter(df, x='mpg', y='hp', color='cyl', marker='origin', title="Auto MPG", xlabel="Miles Per Gallon", ylabel="Horsepower") output_file('scatter.html') show(scatter) """ kws['x'] = x kws['y'] = y kws['series'] = series tools = kws.get('tools', True) if tools == True: tools = "save,resize,reset" elif isinstance(tools, string_types): tools = tools.replace('pan', '') tools = tools.replace('wheel_zoom', '') tools = tools.replace('box_zoom', '') tools = tools.replace(',,', ',') kws['tools'] = tools chart = create_and_build(HorizonBuilder, data, **kws) # Hide numerical axis chart.left[0].visible = False # Add the series names to the y axis chart.extra_y_ranges = {"series": FactorRange(factors=chart._builders[0].series_names)} chart.add_layout(CategoricalAxis(y_range_name="series"), 'left') return chart
def Area(data=None, x=None, y=None, **kws): """ Create an area chart using :class:`AreaBuilder <bokeh.charts.builders.area_builder.AreaBuilder>` to render the geometry from values. Args: data (:ref:`userguide_charts_data_types`): table-like data x (str or list(str), optional): the column label to use for the x dimension y (str or list(str), optional): the column label to use for the y dimension In addition the the parameters specific to this chart, :ref:`userguide_charts_defaults` are also accepted as keyword parameters. Returns: :class:`Chart`: includes glyph renderers that generate the area glyphs Examples: .. bokeh-plot:: :source-position: above from bokeh.charts import Area, show, vplot, output_file # create some example data data = dict( python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111], pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130], jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160], ) area = Area(data, title="Area Chart", legend="top_left", xlabel='time', ylabel='memory') output_file('area.html') show(area) """ kws['x'] = x kws['y'] = y return create_and_build(AreaBuilder, data, **kws)
def Horizon(data=None, x=None, y=None, series=None, **kws): """ Create a horizon chart using :class:`HorizonBuilder <bokeh.charts.builders.scatter_builder.HorizonBuilder>` to render the geometry from values. Args: data (:ref:`userguide_charts_data_types`): table-like data x (str or list(str), optional): the column label to use for the x dimension y (str or list(str), optional): the column label to use for the y dimension In addition to the parameters specific to this chart, :ref:`userguide_charts_defaults` are also accepted as keyword parameters. Returns: :class:`Chart`: includes glyph renderers that generate the scatter points Examples: .. bokeh-plot:: :source-position: above import pandas as pd from bokeh.charts import Horizon, output_file, show # read in some stock data from the Yahoo Finance API AAPL = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=AAPL&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) MSFT = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=MSFT&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) IBM = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=IBM&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) data = dict([ ('AAPL', AAPL['Adj Close']), ('Date', AAPL['Date']), ('MSFT', MSFT['Adj Close']), ('IBM', IBM['Adj Close'])] ) hp = Horizon(data, x='Date', plot_width=800, plot_height=300, title="horizon plot using stock inputs") output_file("horizon.html") show(hp) """ kws['x'] = x kws['y'] = y kws['series'] = series tools = kws.get('tools', True) if tools == True: tools = "save,resize,reset" elif isinstance(tools, string_types): tools = tools.replace('pan', '') tools = tools.replace('wheel_zoom', '') tools = tools.replace('box_zoom', '') tools = tools.replace(',,', ',') kws['tools'] = tools chart = create_and_build(HorizonBuilder, data, **kws) # Hide numerical axis chart.left[0].visible = False # Add the series names to the y axis chart.extra_y_ranges = {"series": FactorRange(factors=chart._builders[0].series_names)} chart.add_layout(CategoricalAxis(y_range_name="series"), 'left') return chart
def Chord(data, source=None, target=None, value=None, square_matrix=False, label=None, xgrid=False, ygrid=False, **kw): """ Create a chord chart using :class:`ChordBuilder <bokeh.charts.builders.chord_builder.ChordBuilder>` to render a chord graph from a variety of value forms. This chart displays the inter-relationships between data in a matrix. The data can be generated by the chart interface. Given a :class:`DataFrame <pandas.DataFrame>`, select two columns to be used as arcs with `source` and `target` attributes, passing by the name of those columns. The :class:`Chord <bokeh.charts.builders.chord_builder.Chord>` chart will then deduce the relationship between the arcs. The value of the connections can be inferred automatically by counting `source` and `target`. If you prefer you can assign a fixed value for all the connections with `value` simply passing by a number. A third option is to pass a reference to a third column in the :class:`DataFrame <pandas.DataFrame>` with the values for the connections. If you want to plot the relationships in a squared matrix, simply pass the matrix and set `square_matrix` attribute to `True`. Reference: `Chord diagram on Wikipedia <https://en.wikipedia.org/wiki/Chord_diagram>`_ Args: data (:ref:`userguide_charts_data_types`): the data source for the chart. source (list(str) or str, optional): Data source to use as origin of the connection to a destination. target (list(str) or str, optional): Data source to use as destination of a connection. value (list(num) or num, optional): The value the connection should have. square_matrix (bool, optional): If square matrix, avoid any calculations during the setup. label (list(str), optional): The labels to be put in the areas. Returns: :class:`Chart`: includes glyph renderers that generate the chord Examples: .. bokeh-plot:: :source-position: above import pandas as pd from bokeh.charts import Chord from bokeh.io import show, output_file from bokeh.sampledata.les_mis import data nodes = data['nodes'] links = data['links'] nodes_df = pd.DataFrame(nodes) links_df = pd.DataFrame(links) source_data = links_df.merge(nodes_df, how='left', left_on='source', right_index=True) source_data = source_data.merge(nodes_df, how='left', left_on='target', right_index=True) source_data = source_data[source_data["value"] > 5] # Select those with 5 or more connections chord_from_df = Chord(source_data, source="name_x", target="name_y", value="value") output_file('chord_from_df.html') show(chord_from_df) """ kw["origin"] = source kw["destination"] = target kw["value"] = value kw["square_matrix"] = square_matrix kw["label"] = label kw['xgrid'] = xgrid kw['ygrid'] = ygrid chart = create_and_build(ChordBuilder, data, **kw) chart.left[0].visible = False chart.below[0].visible = False chart.outline_line_color = None return chart
def Horizon(data=None, x=None, y=None, series=None, **kws): """ Create a horizon chart using :class:`HorizonBuilder <bokeh.charts.builders.scatter_builder.HorizonBuilder>` to render the geometry from values. Args: data (:ref:`userguide_charts_data_types`): table-like data x (str or list(str), optional): the column label to use for the x dimension y (str or list(str), optional): the column label to use for the y dimension In addition to the parameters specific to this chart, :ref:`userguide_charts_defaults` are also accepted as keyword parameters. Returns: :class:`Chart`: includes glyph renderers that generate the scatter points Examples: .. bokeh-plot:: :source-position: above import pandas as pd from bokeh.charts import Horizon, output_file, show # read in some stock data from the Yahoo Finance API AAPL = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=AAPL&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) MSFT = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=MSFT&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) IBM = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=IBM&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) data = dict([ ('AAPL', AAPL['Adj Close']), ('Date', AAPL['Date']), ('MSFT', MSFT['Adj Close']), ('IBM', IBM['Adj Close'])] ) hp = Horizon(data, x='Date', width=800, height=300, title="horizon plot using stock inputs") output_file("horizon.html") show(hp) """ kws['x'] = x kws['y'] = y kws['series'] = series tools = kws.get('tools', True) if tools == True: tools = "save,resize,reset" elif isinstance(tools, string_types): tools = tools.replace('pan', '') tools = tools.replace('wheel_zoom', '') tools = tools.replace('box_zoom', '') tools = tools.replace(',,', ',') kws['tools'] = tools chart = create_and_build(HorizonBuilder, data, **kws) # Hide numerical axis chart.left[0].visible = False # Add the series names to the y axis chart.extra_y_ranges = {"series": FactorRange(factors=chart._builders[0].series_names)} chart.add_layout(CategoricalAxis(y_range_name="series"), 'left') return chart