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
- Installation
- Quick start with Jupyter
- Examples
- SVG/HTML export to file
- Offline mode
- What is new in 1.4.0
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')
Example Notebooks
Try the following examples to study more features of the Lets-Plot library.
-
Quickstart in Jupyter: quickstart.ipynb
-
Histogram, density plot, box plot and facets: distributions.ipynb
-
Error-bars, crossbar, linerange, pointrange, points, lines, bars, dodge position: error_bars.ipynb
-
Points, point shapes, linear regression, jitter position: scatter_plot.ipynb
-
Smoothing: linear, LOESS: geom_smooth.ipynb
-
as_discrete()function: geom_smooth.ipynb -
Points, density2d, polygons, density2df, bin2d: density_2d.ipynb
-
Tiles, contours, polygons, contourf: contours.ipynb
-
Raster geom, Image geom: image_fisher_boat.ipynb
-
Various presentation options: legend_and_axis.ipynb
GeoDataFrame support (Shapely and GeoPandas).
GeoPandas GeoDataFrame is supported by the following geometry layers: geom_polygon, geom_map, geom_point, geom_text, geom_rect.
-
Map building basics with Lets-Plot and GeoPandas: geopandas_naturalearth.ipynb
-
An inset map of Kotlin island: geopandas_kotlin_isl.ipynb
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 fromquickstart. -
geom_density2df()- fills space between equal density lines on a 2D density plot. Similar togeom_density2dbut supports thefillaesthetic.Example: density_2d.ipynb
-
geom_contourf()- fills space between the lines of equal level of the bivariate function. Similar togeom_contourbut supports thefillaesthetic.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.
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.
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_pointgeom_rectgeom_pathgeom_polygongeom_segmentgeom_textgeom_tilegeom_vline,geon_hlinegeom_bin2dgeom_contour,geom_contourfgeom_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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lets_plot-1.4.1-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: lets_plot-1.4.1-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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afeabf6835d21cdf16679180b68114d27b3171b24fb137238ef49f554752e918
|
|
| MD5 |
462dfeae628e6ec6930f58e136eef9b9
|
|
| BLAKE2b-256 |
3f257cc7e5bc688c65c3b4f616d2f536e210f765bfbb9a6be6f704a5082a5a05
|
File details
Details for the file lets_plot-1.4.1-cp38-cp38-manylinux1_x86_64.whl.
File metadata
- Download URL: lets_plot-1.4.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20365222e72dcaf475e183711ff320e443282cee5034a830720229a986d6c2dc
|
|
| MD5 |
6903c9b9fd8c05ba70fc02452cd4fd51
|
|
| BLAKE2b-256 |
fd9f18ea6684434a8e441b6a0d6b39f6e34a6d58e956f9a4f4aceecaaa50e78e
|
File details
Details for the file lets_plot-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl.
File metadata
- Download URL: lets_plot-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae699fd467f12efd284e40f4041f959206d73be5882f7ec36a73c39cd1e48b60
|
|
| MD5 |
2bb1dd9642166ad328c75a9a9f741982
|
|
| BLAKE2b-256 |
cbdbb54e2b6d6b7a3a9a913eeee0891149edb2e2e471d9548e50c9dadbeab127
|
File details
Details for the file lets_plot-1.4.1-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: lets_plot-1.4.1-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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ea5409fb697ea08be18d9adc0c8f4a3d0f580d93e8bb140d34635b79b8c0886
|
|
| MD5 |
58ff116bd0fdac9d90a146cb7f5a52a9
|
|
| BLAKE2b-256 |
df838aa91f92d628518749afac570bddd2b499cb111e33c7f3ea94755903a973
|
File details
Details for the file lets_plot-1.4.1-cp37-cp37m-manylinux1_x86_64.whl.
File metadata
- Download URL: lets_plot-1.4.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd52913e857456390cae281507e08a1acb3844edec2999675f928dd4f2624846
|
|
| MD5 |
23d9910c6cf4c8a18d859de55b1596b5
|
|
| BLAKE2b-256 |
c5fe6dbf36b98add9a2d7dd1a0186d6f528bd3c8a424845ab5d801f6d76d5e9c
|
File details
Details for the file lets_plot-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl.
File metadata
- Download URL: lets_plot-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a307ef1ff3daa99db3c57ec852970ca6b5b2769ad0b3ab89aa798e8e7808cdc0
|
|
| MD5 |
f5fe5189412de18f73e191f65dd81c81
|
|
| BLAKE2b-256 |
d1d1ec8a3f3b5a04a901b9eacb0240603d5f2c9e38ca23e625d659f252bb2fe5
|
File details
Details for the file lets_plot-1.4.1-cp36-cp36m-win_amd64.whl.
File metadata
- Download URL: lets_plot-1.4.1-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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd625d40e96cf58f11f277b51c6960281f234442bdef4d019b4f54a72d0c9683
|
|
| MD5 |
d0226f073033dcdaff387c3d5d9318a6
|
|
| BLAKE2b-256 |
9f604a445b5cd13771977c9f60993b660198661ee886196417d048e03e2be804
|
File details
Details for the file lets_plot-1.4.1-cp36-cp36m-manylinux1_x86_64.whl.
File metadata
- Download URL: lets_plot-1.4.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
674b5332bcd2cec1f5790e38be8d76bec8984261b471b35ae3d767d533c14d69
|
|
| MD5 |
06a6413609350f8a175a6cb98e353870
|
|
| BLAKE2b-256 |
1de53e1b835cb2fb59eaf19002ba147cac5d1e0645ea0cf00d96f375e6a05936
|
File details
Details for the file lets_plot-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl.
File metadata
- Download URL: lets_plot-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbb47a8226f79632b103e44cf4068590997693f0f9fdc1cfa0f5ff9bec672996
|
|
| MD5 |
8f587739776c2097eece4c41d77a2168
|
|
| BLAKE2b-256 |
03880b70bbd6232aa257c8f07a03ae993ef33900e3dfb50590cf8e5b5797c17c
|