Skip to main content

An open source library for statistical plotting

Project description

Lets-Plot for Python official JetBrains project

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

Interactive Maps.

The interactive map allows zooming in and out and panning around geospatial data that can be added to the base-map layer using regular ggplot geoms.

The basemap layer is created by the geom livemap geom which in addition can also work as scatter plot - similar to geom_point.

Learn more about interactive maps support in Lets-Plot.

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.5.0

Geocoding API

Geocoding is the process of converting names of places into geographic coordinates.

Lets-Plot now offers geocoding API covering the following administrative levels:

  • country
  • state
  • county
  • city

Lets-Plot geocoding API allows a user to execute a single and batch geocoding queries, and handle possible names ambiguity.

Relatively simple geocoding queries are executed using the regions_xxx() functions family. For example:

from lets_plot.geo_data import *
regions_country(['usa', 'canada'])

returns the Regions object containing internal IDs for Canada and the US:

  request       id                found name
0     usa   297677  United States of America
1  canada  2856251                    Canada 

More complex geocoding queries can be created with the help of the regions_builder() function that returns the RegionsBuilder object and allows chaining its various methods in order to specify how to handle geocoding ambiguities.

For example:

regions_builder(request='warwick', level='city')  \
    .allow_ambiguous()  \
    .build()

This sample returns the Regions object containing IDs of all cities matching "warwick":

    request        id                   found name
0   warwick    785807                      Warwick
1   warwick    363189                      Warwick
2   warwick    352173                      Warwick
3   warwick  15994531                      Warwick
4   warwick    368499                      Warwick
5   warwick    239553                      Warwick
6   warwick    352897                      Warwick
7   warwick   3679247                      Warwick
8   warwick   8144841                      Warwick
9   warwick    382429                 West Warwick
10  warwick   7042961             Warwick Township
11  warwick   6098747             Warwick Township
12  warwick  15994533  Sainte-Élizabeth-de-Warwick
boston_us = regions(request='boston', within='us')
regions_builder(request='warwick', level='city') \
    .where('warwick', near=boston_us) \
    .build()

This example returns the Regions object containing the ID of one particular "warwick" near Boston (US):

   request      id found name
0  warwick  785807    Warwick

Once the Regions object is available, it can be passed to any Lets-Plot geom supporting the map parameter.

If necessary, the Regions object can be transformed into a regular pandas DataFrame using to_data_frame() method or to a geopandas GeoDataFrame using one of centroids(), boundaries(), or limits() methods.

All coordinates are in the EPSG:4326 coordinate reference system (CRS).

Note what executing geocoding queries requires an internet connection.

Examples:

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

This version

1.5.1

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

If you're not sure about the file name format, learn more about wheel file names.

lets_plot-1.5.1-cp38-cp38-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8

lets_plot-1.5.1-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.1-cp37-cp37m-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.7m

lets_plot-1.5.1-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.1-cp36-cp36m-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.6mWindows x86-64

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

Uploaded CPython 3.6m

lets_plot-1.5.1-cp36-cp36m-macosx_10_7_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.6mmacOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for lets_plot-1.5.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9b1e5d7a1465ac1f19c3a9731b7e2cf15a506ed57a3d4dd25022243f5a4e3c44
MD5 73100ad5d0f3c355d467445d5b120a60
BLAKE2b-256 9533c0b7eb0845a0508495b2ee60b554e335e0e70c33ce3298b9432e33bfe1ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 253cb90e7787f6f00c08c43b40d7c411fcdcf28993165130575e1ec34739fb0d
MD5 c7bed9aec518ab3f949247004a6b3e55
BLAKE2b-256 8ff98189fe901fec1dc73e035ff28f758ffebc53f9ff36775d3cbcdd3d5b6309

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191201 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for lets_plot-1.5.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ebb9cd7b5b4051eaff8ffc2d900f89722f1a0a3a4d7a3ab4285c7c2b897768fc
MD5 98ae03a847b1baa46dd390acb4863c74
BLAKE2b-256 516c53a60b0d4ea68de5157cb6a4b316094148c5e00e0e48d131fc1243f545b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for lets_plot-1.5.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ec43b99c3baf248f784cb26304d2aaaad20f1d8c63d18f236499d7aa3c9d01e1
MD5 bc96879c91b5fca21b6b47f1534a5d09
BLAKE2b-256 6623e61a2504b41d48b0a3e69e1a5cc150a0d20d4cdc1c7b4e71d54d56f418ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e3b1a7149ba4d6af21658eb1c1593b1ac6e0cb6e2a49eaa844fee3c96323300b
MD5 8a99fe5c36bb0b3e21cc074d480b8018
BLAKE2b-256 b2f6c4f7b12994f9c3aa366f216574a5b7c418f8a25e41c8b3d85a4b33477ac3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191201 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for lets_plot-1.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dc4979ef5d093c0e7b53b81f9e413eb229cfb80f5c7bd1370ca3217acccaf423
MD5 72a9857f2c9c088f4857a725971b19bd
BLAKE2b-256 8c5ece1b890a125272875381dc40827f06d05942ee1294ba89fc408e2744937f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for lets_plot-1.5.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b479d000119ad16396570be427f53a527f9cab10649c0f2035064c26b527d14b
MD5 a083d796b1a0ad47b17b74e9485a305c
BLAKE2b-256 d3c51e59b55ceb7ef4b41ee2dee653886f13c7d750022836a56edab7d61cbc9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lets_plot-1.5.1-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.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5f0ee0c2ee3ae52292a7082a136961c3ed73d026e2aa7abb7e7e5eda5eb02bcc
MD5 2356c14419677166db92a737506d580e
BLAKE2b-256 ffafacf6501268c55da34776985cfab9da03911481c41c67c1dcb6ab8dd42f41

See more details on using hashes here.

File details

Details for the file lets_plot-1.5.1-cp36-cp36m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: lets_plot-1.5.1-cp36-cp36m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.6m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191201 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for lets_plot-1.5.1-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 36b8779d8c33971b4cb8ad2e754ea539c53e0f311dcd5373835b05018f3f9878
MD5 a75895a173dd4f91d0e437ba1da0e4ff
BLAKE2b-256 d6e13bac181d98d352eefa1385d3d6930a14208f03a83cdae9d53e7468753174

See more details on using hashes here.

Supported by

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