spotify / chartify

Python library that makes it easy for data scientists to create charts.
Apache License 2.0
3.54k stars 324 forks source link

Add Bokeh gridplot/layout integration #40

Open elansparsons opened 6 years ago

elansparsons commented 6 years ago

Is this a BUG REPORT or FEATURE REQUEST?: type: feature

Currently, when attempting to use gridplot with Chartify (as a list of charts), it returns "AttributeError: 'Chart' object has no attribute 'select'." When attempting the same with bokeh.layouts.layout, it returns "ValueError: Only LayoutDOM items can be inserted into a layout."

It would be great to have this feature integrated to show/export many chart objects at once.

cphalpert commented 6 years ago

Thanks for the suggestion! Better grids and layouts would be a good addition. Here's an example of how you can use Chartify with gridplot in the meantime until we come up with a better solution. Just need to create a list of figure objects from your chartify.Chart objects:

import chartify
from bokeh.layouts import gridplot
from bokeh.io import show

chart_1 = chartify.Chart(layout='slide_50%').set_title('Chart 1')
chart_2 = chartify.Chart(layout='slide_50%').set_title('Chart 2')
chart_3 = chartify.Chart().set_title('Chart 3')

# Create a list of figure objects to pass to gridplot
chart_figures = [chart.figure for chart in (chart_1, chart_2, chart_3)]

# make a grid
grid = gridplot(chart_figures, ncols=2,)

# show the results
show(grid)
elansparsons commented 6 years ago

Great, thanks for the workaround!

leemengtw commented 6 years ago

This is a helpful workaround, can't wait more chartify-way to create a grid! :)