简体   繁体   English

Python+Altair (Vega-Lite):网络服务器

[英]Python+Altair (Vega-Lite): Web server

I want to visualize some graphs on web pages using Python 2.7.12 and Altair 1.2.0.我想使用 Python 2.7.12 和 Altair 1.2.0 在网页上可视化一些图表。

Using their examples it is easy and straightforward:使用他们的示例简单明了:

from altair import *
from altair import Chart, load_dataset

# load built-in dataset as a pandas DataFrame
cars = load_dataset('cars')

chart = Chart(cars).mark_circle().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)

chart.display()  

This works in Jupyter Notebook.这适用于 Jupyter Notebook。

Changing chart.display() to chart.server() (as described at https://altair-viz.github.io/documentation/displaying.html#displaying-plots-via-a-local-http-server ) should be enough to start a web server using Python's HTTPServer.chart.display()更改为chart.server() (如https://altair-viz.github.io/documentation/displaying.html#displaying-plots-via-a-local-http-server所述)应该是足以使用 Python 的 HTTPServer 启动 Web 服务器。

It starts, but the page it provides is empty.它启动了,但它提供的页面是空的。 The source is there but nothing is visualized.来源在那里,但没有任何可视化。

Any idea about why?知道为什么吗?

Adding my previous comment as an answer:添加我之前的评论作为答案:

chart.serve() is working as expected for me (altair 2.1.0). chart.serve() 按我的预期工作(altair 2.1.0)。 The documentation has moved to here https://altair-viz.github.io/user_guide/display_frontends.html?e#working-in-non-notebook-environments文档已移至此处https://altair-viz.github.io/user_guide/display_frontends.html?e#working-in-non-notebook-environments

from altair import Chart, load_dataset

# load built-in dataset as a pandas DataFrame
cars = load_dataset('cars')

chart = Chart(cars).mark_circle().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)

chart.serve() 

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

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