Skip to main content

An open source library for statistical plotting

Project description

Lets-Plot for Python

Latest Release
License
OS Linux, MacOS, Windows
Python versions 3.6, 3.7, 3.8

Implementation Overview

The Lets-Plot python extension includes native backend and a Python API, which was mostly based on the ggplot2 package well-known to data scientists who use R.

R ggplot2 has extensive documentation and a multitude of examples and therefore is an excellent resource for those who want to learn the grammar of graphics.

Note that the Python API being very similar yet is different in detail from R. Although we have not implemented the entire ggplot2 API in our Python package, we have added a few new features to our Python API.

You can try the Lets-Plot library in Datalore. Lets-Plot is available in Datalore out-of-the-box and is almost identical to the one we ship as PyPI package. This is because Lets-Plot is an offshoot of the Datalore project from which it was extracted to a separate plotting library.

One important difference is that the python package in Datalore is named datalore.plot and the package you install from PyPI has name lets_plot.

The advantage of Datalore as a learning tool in comparison to Jupyter is that it is equipped with very friendly Python editor which comes with auto-completion, intentions, and other useful coding assistance features.

Installation

To install the Lets-Plot library, run the following command:

pip install lets-plot

Quick start with Jupyter

To evaluate the plotting capabilities of Lets-Plot, add the following code to a Jupyter notebook:

import numpy as np
from lets_plot import *
LetsPlot.setup_html()        

np.random.seed(12)
data = dict(
    cond=np.repeat(['A','B'], 200),
    rating=np.concatenate((np.random.normal(0, 1, 200), np.random.normal(1, 1.5, 200)))
)

ggplot(data, aes(x='rating', fill='cond')) + ggsize(500, 250) \
+ geom_density(color='dark_green', alpha=.7) + scale_fill_brewer(type='seq') \
+ theme(axis_line_y='blank')
Couldn't load quickstart.png


Example Notebooks

Try the following examples to study more features of the Lets-Plot library.

GeoDataFrame support (Shapely and GeoPandas).

GeoPandas GeoDataFrame is supported by the following geometry layers: geom_polygon, geom_map, geom_point, geom_text, geom_rect.

Couldn't load kotlin_island.png

Nonstandard plotting functions

The following features of Lets-Plot are not available or have different implementation in other Grammar of Graphics libraries.

  • ggsize() - sets the size of the plot. Used in many examples starting from quickstart.

  • geom_density2df() - fills space between equal density lines on a 2D density plot. Similar to geom_density2d but supports the fill aesthetic.

    Example: density_2d.ipynb

  • geom_contourf() - fills space between the lines of equal level of the bivariate function. Similar to geom_contour but supports the fill aesthetic.

    Example: contours.ipynb

  • geom_image() - displays an image specified by a ndarray with shape (n,m) or (n,m,3) or (n,m,4).

    Example: image_101.ipynb

    Example: image_fisher_boat.ipynb

  • gg_image_matrix() - a utility helping to combine several images into one graphical object.

    Example: image_matrix.ipynb

GGBanch

GGBunch allows to show a collection of plots on one figure. Each plot in the collection can have arbitrary location and size. There is no automatic layout inside the bunch.

Examples:

Data sampling

Sampling is a special technique of data transformation, which helps dealing with large datasets and overplotting.

Learn more about sampling in Lets-Plot.

Artistic demos

A set of interesting notebooks using Lets-Plot library for visualization.
Couldn't load klein_bottle.png

What is new in 1.3.0

SVG/HTML export to file.

export_svg function takes plot specification and filename as parameters and saves SVG representation of the plot to a file in the current working directory.

from lets_plot import *
p = ggplot()...

# export SVG to file
from lets_plot.export.simple import export_svg

export_svg(p, "p.svg")

export_html function takes plot specification and filename as parameters and saves dynamic HTML to a file in the current working directory. When viewing this content the internet connection is required.

export_html has one more option - iframe. If iframe=True then Lets-PLot will wrap output HTML into iframe.

from lets_plot import *
p = ggplot()...

# export HTML to file
from lets_plot.export.simple import export_html

export_html(p, "p.htm")

Example notebook: export_SVG_HTML

Offline mode for Jupyter notebooks.

In classic Jupyter notebook the LetsPlot.setup_html() statement by default pre-loads Lets-Plot JS library from CDN. Alternatively, option offline=True will force Lets-Plot adding the full Lets-Plot JS bundle to the notebook. In this case, plots in the notebook will be working without an Internet connection.

from lets_plot import *

LetsPlot.setup_html(offline=True)

Cloud-based notebooks are supported (like Google Colab, JetBrains Datalore)

Example of Google Colab notebook: quickstart.ipynb

Change Log

See Lets-Plot at Github.

License

Code and documentation released under the MIT license. Copyright 2019, JetBrains s.r.o.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lets-plot, version 1.3.0
Filename, size File type Python version Upload date Hashes
Filename, size lets_plot-1.3.0-cp36-cp36m-macosx_10_7_x86_64.whl (4.2 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp36-cp36m-manylinux1_x86_64.whl (4.9 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp36-cp36m-win_amd64.whl (2.8 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp37-cp37m-macosx_10_9_x86_64.whl (4.0 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp37-cp37m-manylinux1_x86_64.whl (4.9 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp37-cp37m-win_amd64.whl (2.8 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp38-cp38-macosx_10_9_x86_64.whl (4.0 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp38-cp38-manylinux1_x86_64.whl (4.9 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size lets_plot-1.3.0-cp38-cp38-win_amd64.whl (2.8 MB) File type Wheel Python version cp38 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page