Code Monkey home page Code Monkey logo

altair_viewer's Introduction

Altair Viewer

Offline chart viewer for Altair visualizations

github actions github actions code style black

This package provides tools for viewing Altair charts without a web connection in arbitrary Python environments. Charts can be displayed either inline in a Jupyter notebook environment, or in a separate browser window for use in any environment.

Altair Viewer Gif

Installation

Altair Viewer can be installed from the Python Package Index with pip:

$ pip install altair_viewer

Usage: General Environments

Altair viewer provides two top-level functions for displaying charts: display() and show(). Their intended use is slightly different:

import altair_viewer
altair_viewer.display(chart)

display(chart) is meant for use in interactive computing environments where a single Python process is used interactively. It will serve a chart viewer at a localhost URL, and any susequent chart created within the session will appear in the same window. The background server will be terminated when the main Python process terminates, so this is not suitable for standalone scripts.

import altair_viewer
altair_viewer.show(chart)

show(chart) is meant for use once at the end of a Python script. It does the same as display(), but automatically opens a browser window, and adds an input prompt to prevent the script (and the server it creates) from terminating.

Usage: IPython & Jupyter

Within Jupyter notebook, IPython terminal, and related environments that support Mimetype-based display, altair viewer can be used by enabling the altair_viewer renderer:

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

This will cause charts at the end of a Jupyter notebook cell to be rendered in a separate browser window, as with the display() and show() methods.

If enabled with inline=True, charts will be rendered inline in the notebook:

import altair as alt
alt.renderers.enable('altair_viewer', inline=True)

To display a single inline chart using Altair viewer in an IPython environment without globally enabling the associated renderer, you can use the display method directly:

import altair_viewer
altair_viewer.display(chart, inline=True)

Note that the display based on altair viewer will only function correctly as long as the kernel that created the charts is running, as it depends on the background server started by the kernel. In particular, this means that if you save a notebook and reopen it later, charts will not display until the associated cells are re-run.

altair_viewer's People

Contributors

jakevdp avatar xhochy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.