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

1. For Linux and Mac users:

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

pip install lets-plot

2. For Windows users:

Install Anaconda3 (or Miniconda3), then install MinGW toolchain to Conda:

conda install m2w64-toolchain

Install the Lets-Plot library:

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.

Cloud-based notebooks

Examples:

Interesting demos

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

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")

Note: The simple.export_svg() function do not save images of an interactive map.

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

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)

What is new in 1.4.0

Interactive maps

Function geom_livemap() enables a researcher to visualize geospatial information on interactive map.

Couldn't load map_path.png

When building interactive geospatial visualizations with Lets-Plot the visualisation workflow remains the same as when building a regular ggplot2 plot.

However, geom_livemap() creates an interactive base-map super-layer and certain limitations do apply comparing to a regular ggplot2 geom-layer:

  • geom_livemap() must be added as a 1-st layer in plot;
  • Maximum one geom_livemap() layer is alloed per plot;
  • Not any type of geometry can be combined with interactive map layer in one plot;
  • Internet connection to map tiles provider is required.

The following ggplot2 geometry can be used with interactive maps:

  • geom_point
  • geom_rect
  • geom_path
  • geom_polygon
  • geom_segment
  • geom_text
  • geom_tile
  • geom_vline, geon_hline
  • geom_bin2d
  • geom_contour, geom_contourf
  • geom_density2d, geom_density2df

Examples:

Function as_discrete()

The function as_discrete() is used to annotate a numeric data series as categorical data for the purposes of given visualization.

Code example:

from lets_plot.mapping import as_discrete

mpg_plot + geom_point(aes(color='cyl'))\
         + geom_smooth(aes(color=as_discrete('cyl')), method='lm', deg=2, size=1)

Example notebook: geom_smooth.ipynb

Polynomial regression of arbitrary degree in geom_smooth

New parameter deg in geom_smooth() allows to adjust the degree of the model polynomial when using linear model smoothing method.

Code example:

# Apply 2nd degree polynomial regression 
p + geom_smooth(method='lm', deg=2)

Example notebook: geom_smooth.ipynb

Hiding tooltips on axis

There are new parameters axis_tooltip, axis_tooltip_x and axis_tooltip_y in the function theme() which allow to hide tooltip on axis X, axis Y or on the both axis.

Code example:

# Hide tooltips on both axis.
p + theme(axis_tooltip='blank')

Change Log

See Lets-Plot at Github.

License

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

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

lets_plot-1.4.0-cp38-cp38-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.8Windows x86-64

lets_plot-1.4.0-cp38-cp38-manylinux1_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8

lets_plot-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

lets_plot-1.4.0-cp37-cp37m-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.7mWindows x86-64

lets_plot-1.4.0-cp37-cp37m-manylinux1_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.7m

lets_plot-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

lets_plot-1.4.0-cp36-cp36m-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.6mWindows x86-64

lets_plot-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.6m

lets_plot-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

Details for the file lets_plot-1.4.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0.post20200511 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 67e79fac2187b06349ac63a403b8a64446b4ac3edf985e689046ddd633fa256a
MD5 9667415f709be834776d2fc1b26bbb38
BLAKE2b-256 b080a755aa9d2e4a93d34712dc53a346b5e58046c8f6f564ae47084337f7d4ab

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4ad6b0248617914aab93cb68f3743ea082786c0c15b411859fcc098b368b9749
MD5 bdd9a475b1c477de2e9193678e77641c
BLAKE2b-256 432b1686f6151568c9176c8f62cf251a8a61b04a81a2312e908c9fc99d7b3f98

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9f8eb48ea7cf7950c708b564aacae855fe8d96a4912c3fb84b565491cd4f1126
MD5 15e11edeaca1264979e54b14e5635fe3
BLAKE2b-256 8cd2216625555f8ed5f1f6ea971c5d71052f4442718a9f3f916d75874a4455ff

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0.post20200511 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4dfc784d02b820b4a9cefdc290b0100217c22204ef50708bf2d31d2be1f86498
MD5 f21c6de8a0a53567a8a0643979163369
BLAKE2b-256 8c88237dbeb4fdbcccbf3106646571d385278a1e701cd93dc12abe7afd4b31d5

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 70ef6a4d8288dd7b8faa9bf08eac05293c57e701d2bd6cfe4d1d6737c752f7c7
MD5 f86c08864a0c7185fb8d41edc3e26d09
BLAKE2b-256 e1057f99983cfa1b16177e4430fac65f54d88f612cadf11c1f01116c96002ab4

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ebb4a02288b1818c693d4a7459410a88c66cf47be369c14acbf1833c007831f2
MD5 564e5776a51be650c4a658d2601613bf
BLAKE2b-256 3a0a3d241e3c8defec69f9e08bfc17e74a4646fa67c98c1b28b7115d457010f4

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0.post20200511 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 0f78599a493f3c9cfa45e9bf073e549570c0c6e69c39570909b3423ef45b4222
MD5 93b43ec1ec06ea2cc8b7ed0c461f8afc
BLAKE2b-256 ccc13b73401bfc15d366dca201da8263cbd978bc306aa3f06a7dab6e94bcd224

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bb490732c1d7398ec7c1310dff38822d97a7139e87862a525b89d40aaf1ca67d
MD5 81795a720e203979e0ba429abf801663
BLAKE2b-256 bfb3cb7ecb413f4be6e98c91602bf91e465997c9969616e9f6402e5d5280f279

See more details on using hashes here.

File details

Details for the file lets_plot-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lets_plot-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b46c0cb202e777bceed7acefa4853272e8546a1a73721ee94bd7ce729e635a67
MD5 848bfd3ab4767a0bb812ed42088c9346
BLAKE2b-256 62c86e154eb4505a88e3f27afc339ee747aec6b383c8a2bdd796e95d00cbc263

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page