Python Holoviews示例:如何在Jupyter笔记本中显示绘图?

Python Holoviews示例:如何在Jupyter笔记本中显示绘图?,python,jupyter-notebook,data-visualization,jupyter,holoviews,Python,Jupyter Notebook,Data Visualization,Jupyter,Holoviews,我是第一次尝试Holoviews,我想复制这个动画“Gapminder”的情节 代码可以运行,但我不知道如何处理输出,以便将其显示在Jupyter笔记本中(我假设这是可能的,因为Jupyter可以显示任意HTML) 具体地说,我应该如何处理生成的doc或hvplot对象?这个特定示例结合了HoloView和bokeh组件,而bokeh小部件无法轻松地与笔记本中的Python通信。但是,您可以使用holoviews“洗涤器”小部件实现相同的功能: import pandas as pd impor

我是第一次尝试Holoviews,我想复制这个动画“Gapminder”的情节

代码可以运行,但我不知道如何处理输出,以便将其显示在Jupyter笔记本中(我假设这是可能的,因为Jupyter可以显示任意HTML)


具体地说,我应该如何处理生成的
doc
hvplot
对象?

这个特定示例结合了HoloView和bokeh组件,而bokeh小部件无法轻松地与笔记本中的Python通信。但是,您可以使用holoviews“洗涤器”小部件实现相同的功能:

import pandas as pd
import numpy as np
import holoviews as hv
from bokeh.sampledata import gapminder

hv.extension('bokeh')

# Switch to sending data 'live' and using the scrubber widget
%output widgets='live' holomap='scrubber'

# Declare dataset
panel = pd.Panel({'Fertility': gapminder.fertility,
                  'Population': gapminder.population,
                  'Life expectancy': gapminder.life_expectancy})
gapminder_df = panel.to_frame().reset_index().rename(columns={'minor': 'Year'})
gapminder_df = gapminder_df.merge(gapminder.regions.reset_index(), on='Country')
gapminder_df['Country'] = gapminder_df['Country'].astype('str')
gapminder_df['Group'] = gapminder_df['Group'].astype('str')
gapminder_df.Year = gapminder_df.Year.astype('f')
ds = hv.Dataset(gapminder_df)

# Apply dimension labels and ranges
kdims = ['Fertility', 'Life expectancy']
vdims = ['Country', 'Population', 'Group']
dimensions = {
    'Fertility' : dict(label='Children per woman (total fertility)', range=(0, 10)),
    'Life expectancy': dict(label='Life expectancy at birth (years)', range=(15, 100)),
    'Population': ('population', 'Population')
}

# Create Points plotting fertility vs life expectancy indexed by Year
gapminder_ds = ds.redim(**dimensions).to(hv.Points, kdims, vdims, 'Year')

# Define annotations
text = gapminder_ds.clone({yr: hv.Text(1.2, 25, str(int(yr)), fontsize=30)
                           for yr in gapminder_ds.keys()})

# Define options
opts = {'plot': dict(width=1000, height=600,tools=['hover'], size_index='Population',
                     color_index='Group', size_fn=np.sqrt, title_format="{label}"),
       'style': dict(cmap='Set1', size=0.3, line_color='black', alpha=0.6)}
text_opts = {'style': dict(text_font_size='52pt', text_color='lightgray')}


# Combine Points and Text
(gapminder_ds({'Points': opts}) * text({'Text': text_opts})).relabel('Gapminder Demo')
import pandas as pd
import numpy as np
import holoviews as hv
from bokeh.sampledata import gapminder

hv.extension('bokeh')

# Switch to sending data 'live' and using the scrubber widget
%output widgets='live' holomap='scrubber'

# Declare dataset
panel = pd.Panel({'Fertility': gapminder.fertility,
                  'Population': gapminder.population,
                  'Life expectancy': gapminder.life_expectancy})
gapminder_df = panel.to_frame().reset_index().rename(columns={'minor': 'Year'})
gapminder_df = gapminder_df.merge(gapminder.regions.reset_index(), on='Country')
gapminder_df['Country'] = gapminder_df['Country'].astype('str')
gapminder_df['Group'] = gapminder_df['Group'].astype('str')
gapminder_df.Year = gapminder_df.Year.astype('f')
ds = hv.Dataset(gapminder_df)

# Apply dimension labels and ranges
kdims = ['Fertility', 'Life expectancy']
vdims = ['Country', 'Population', 'Group']
dimensions = {
    'Fertility' : dict(label='Children per woman (total fertility)', range=(0, 10)),
    'Life expectancy': dict(label='Life expectancy at birth (years)', range=(15, 100)),
    'Population': ('population', 'Population')
}

# Create Points plotting fertility vs life expectancy indexed by Year
gapminder_ds = ds.redim(**dimensions).to(hv.Points, kdims, vdims, 'Year')

# Define annotations
text = gapminder_ds.clone({yr: hv.Text(1.2, 25, str(int(yr)), fontsize=30)
                           for yr in gapminder_ds.keys()})

# Define options
opts = {'plot': dict(width=1000, height=600,tools=['hover'], size_index='Population',
                     color_index='Group', size_fn=np.sqrt, title_format="{label}"),
       'style': dict(cmap='Set1', size=0.3, line_color='black', alpha=0.6)}
text_opts = {'style': dict(text_font_size='52pt', text_color='lightgray')}


# Combine Points and Text
(gapminder_ds({'Points': opts}) * text({'Text': text_opts})).relabel('Gapminder Demo')