简体   繁体   English

保存为 HTML 时无法呈现 Altair 图表

[英]Unable to render Altair chart when saved as HTML

I am using Altair to develop an interactive chart.我正在使用 Altair 开发交互式图表。 Altair uses plotly in background. Altair 在后台使用 plotly。 Until yesterday I was able to download the interactive chart as an HTML and open in web-browser, still being able to use it interactively.直到昨天,我才能够将交互式图表下载为 HTML 并在网络浏览器中打开,仍然可以交互式使用它。 However, now I unable to use it interactively, and it is like a static chart when I open the HTML.但是,现在无法交互使用,打开HTML就像静态图表一样。 The interactivity is there when seen in the jupyter notebook.在 jupyter notebook 中可以看到交互性。

I am unsure, but javascript usually helps in rendering the interactivity.我不确定,但 javascript 通常有助于呈现交互性。 This possibly happened after I update my MacOS.这可能发生在我更新我的 MacOS 之后。

import altair as alt
alt.renderers.enable('notebook')

def plot_anomalies(forecasted):
    alt.data_transformers.disable_max_rows()
    interval = alt.Chart(forecasted).mark_area(interpolate="basis", color = '#7FC97F').encode(
    x=alt.X('ds:T',  title ='date'),
    y='yhat_upper',
    y2='yhat_lower',
    tooltip=['ds', 'fact', 'regions', 'az']).interactive().properties(title='Anomaly Detection')

    fact = alt.Chart(forecasted[forecasted.anomaly==0]).mark_circle(size=15, opacity=0.7, color = 'Black').encode(
        x='ds:T',
        y=alt.Y('fact', title='usage percent'),    
        tooltip=['ds', 'fact']).interactive()

    anomalies = alt.Chart(forecasted[forecasted.anomaly!=0]).mark_circle(size=30, color = 'Red').encode(
        x='ds:T',
        y=alt.Y('fact', title='usage percent'),    
        tooltip=['ds', 'fact', 'regions', 'az'],
        size = alt.Size( 'importance', legend=None)).interactive()

    return alt.layer(interval, fact, anomalies)
              .properties(width=870, height=350)
              .configure_title(fontSize=20)

I save the return object pred as pred.save('Name.html')我将返回对象 pred 保存为 pred.save('Name.html')

No longer reproducible as per the comment of the OP.根据 OP 的评论,不再可重现。 No reason provided as to why.没有说明原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM