0

我已经创建了一个带有fastpages的网页。我可以轻松地.ipynb直接制作带有文件的博客页面。例如,使用下面的代码.ipynb,我可以轻松地显示结果plotly

import numpy as np
import geopandas as gpd
import plotly.express as px
from IPython.display import HTML

#  GeoJson from French Open-Data (french department)
lyr = "./data/Southern_Zagros.geojson"

# Read file with geopandas
geo_df = gpd.read_file(lyr)
#geo_df['random_color'] = np.random.randint(1, 2, geo_df.shape[0])
fig = px.choropleth_mapbox(geo_df, 
                           geojson=geo_df.geometry, 
                           locations=geo_df.index,
                           center={"lat": 29.8, "lon": 52.8},
                           mapbox_style="open-street-map",
                           hover_data=["Name"],
                           opacity = 0.5,
                           zoom=5)
fig.update_layout(margin={"r":100,"t":20,"l":20,"b":20})
#fig.show()
HTML(fig.to_html(include_plotlyjs='cdn'))

我想在 jupyter notebook 文件中使用,并通过上面的例子Panel将其转换为网页。fastpages我尝试了下面的示例代码,但它的情节没有显示在博客页面中。有可能做到吗?

import hvplot.pandas
from bokeh.sampledata.autompg import autompg

def autompg_plot(x='mpg', y='hp', color='#058805'):
    return autompg.hvplot.scatter(x, y, c=color, padding=0.1)

columns = list(autompg.columns[:-2])

x = pn.widgets.Select(value='mpg', options=columns, name='x')
y = pn.widgets.Select(value='hp', options=columns, name='y')
color = pn.widgets.ColorPicker(name='Color', value='#880588')

layout = pn.Row(
    pn.Column('## MPG Explorer', x, y, color),
    autompg_plot(x.value, y.value, color.value))

def update(event):
    layout[1].object = autompg_plot(x.value, y.value, color.value)

x.param.watch(update, 'value')
y.param.watch(update, 'value')
color.param.watch(update, 'value')

layout
4

0 回答 0