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.

Quickstart and more

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)

Scientific mode in IntelliJ IDEA / PyCharm

JetBrains Plugins JetBrains plugins

Plugin "Lets-Plot in SciView" is available at the JetBrains Plugin Repository.

The plugin adds support for interactive plots in IntelliJ-based IDEs with the enabled Scientific mode.

To learn more about the plugin check: Lets-Plot in SciView plugin homepage.

Couldn't load pycharm_quickstart.png Couldn't load pycharm_logo.png

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.5.0-cp38-cp38-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.8Windows x86-64

lets_plot-1.5.0-cp38-cp38-manylinux1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8

lets_plot-1.5.0-cp38-cp38-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

lets_plot-1.5.0-cp37-cp37m-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.7mWindows x86-64

lets_plot-1.5.0-cp37-cp37m-manylinux1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.7m

lets_plot-1.5.0-cp37-cp37m-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

lets_plot-1.5.0-cp36-cp36m-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.6mWindows x86-64

lets_plot-1.5.0-cp36-cp36m-manylinux1_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.6m

lets_plot-1.5.0-cp36-cp36m-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.3 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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for lets_plot-1.5.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8ba7edd7d087e7035b3d4b7ad8d5464453a298a27078867a5d8bee0c77313f71
MD5 58f31f928bdb6b5e00b47d37bb58cf31
BLAKE2b-256 045968c2269f3f4380726af32bebb4c6affa1a2c8d9b220aaa044db6a3e38ec3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.7 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.5.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d8bbd86ac0cc9b1741a3e24081ce66ec1205491ded674ab956b340d47950fcd5
MD5 3ba081744e60ec24b86eab2e59b590eb
BLAKE2b-256 2048724c1d4442bf28bf7ce5627833cff567f970082ef8a9fce9ca6dd247a108

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 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.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4d56fa74c140b104a528b2794a389b4c67b29c6fa92d260f6059b730a9ff464d
MD5 11d8a5be91e494d96a375af3d2c17c48
BLAKE2b-256 5d09657371de91bb118a1795256edd7895882006a8507abb19653cb92ca69660

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.3 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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for lets_plot-1.5.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ebda51e225b8af4c14c929b4a125179776195b81f5483430e04af8c1895fa90d
MD5 6f5e0c75c824683884932787b5bc03ac
BLAKE2b-256 966f73aed94b0370ec160814220fee1d3968e753abc90807087ce8b738e5e78e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.7 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.5.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 20bac130faac51e3464ee69f671cb79aa7fd150c69ab3d0aca5b2a904565c58f
MD5 155a8991b901cb3b9e6b17844faccc6e
BLAKE2b-256 adf6884c2c81942eaaf27f05a52f05b1083546daf1dc84405ca38069a10ff5af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 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.5.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 67e142d2278d09566a87af57a7e4b55bac6b871cf187e561d8be6df2f2ade4bf
MD5 65cbf1e8f8998f7a1a18569188000181
BLAKE2b-256 3c19fa0b01601501359892e43de9bc57cbbb5676453091da6296740cc700cc37

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.3 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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for lets_plot-1.5.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 dbdbfac6b3a8f77292bff408580a7cbbe3555e713f16b7bf0c8ed0573bc53144
MD5 c2317ec206e0b51cba111638dd492a96
BLAKE2b-256 8a2005e17f1900c102be567ad3c026343c2305af8033eef15ca978058c74230a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.7 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.5.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 85423fbad7cdfd273ed733b6d54b30638bdea11b2578fac47822d426fe4eb219
MD5 ab34fb120ffdb77635f3b2580a8bdf8b
BLAKE2b-256 6ec85774d4b56771320d3e73cd483614835f727ddef5f41a5c00464d946f80fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 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.5.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bc0b54a435e9ff4b79e1df28135c31765298a4889de71cc7b5c809a47d6e4f45
MD5 3fd6685c98efa64d5677c312753ae8f1
BLAKE2b-256 974da4bb07ec3b07e0eac78131e71923069bd6313f835d3c2756fdbc01265f23

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