### Install Lets-Plot Source: https://lets-plot.org/python/index.html Install the Lets-Plot library using pip. ```bash pip install lets-plot ``` -------------------------------- ### Setup External Display - Default Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Configures Lets-Plot to display plots in an external web browser. This example uses the default browser settings. ```python # Show the plot in the default web browser. from lets_plot import * LetsPlot.setup_show_ext() p = ggplot() + geom_point(x=0, y=0) p.show() ``` -------------------------------- ### Basic Discrete Fill Scale with Hidden Guide Source: https://lets-plot.org/python/pages/api/lets_plot.scale_fill_discrete.html This example demonstrates how to use scale_fill_discrete to set a discrete fill color scale for points and hide the associated guide. It requires importing numpy and lets_plot, and setting up the HTML environment. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(100) n = 50 x = np.random.rand(n) y = np.random.rand(n) z = np.random.rand(n) ggplot() + geom_point(aes(x, y, fill=z), shape=21, size=4, color='gray') + \ scale_fill_discrete(guide='none') ``` -------------------------------- ### Basic Discrete Color Scale with Hidden Guide Source: https://lets-plot.org/python/pages/api/lets_plot.scale_color_discrete.html This example demonstrates how to create a scatter plot with discrete colors based on a data variable 'z' and hide the color guide. It requires importing necessary libraries and setting up Lets-Plot. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(100) n = 50 x = np.random.rand(n) y = np.random.rand(n) z = np.random.rand(n) ggplot() + geom_point(aes(x, y, color=z), size=4) + \ scale_color_discrete(guide='none') ``` -------------------------------- ### Basic Dotplot Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_dotplot.html A simple example demonstrating how to create a basic dotplot using geom_dotplot with default settings. ```APIDOC ## Example 1: Basic Dotplot ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) data = {'x': np.random.normal(size=100)} ggplot(data, aes(x='x')) + geom_dotplot() ``` ``` -------------------------------- ### Basic geom_step Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_step.html A basic example of using geom_step to connect sequential data points. Requires numpy and lets_plot libraries. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() n = 20 np.random.seed(42) x = np.arange(n) y = np.random.randint(5, size=n) ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + geom_step() + coord_fixed() ``` -------------------------------- ### Configure Raster Tiles with URL Parameters Source: https://lets-plot.org/python/pages/basemap_tiles.html This example shows how to include additional key-value pairs as parameters in the tile URL, such as an access key. This is useful for tile services that require authentication or specific query parameters. ```python maptiles_zxy(url='http://maps.example.com/{z}/{x}/{y}.png?access_key={key}', key='MY_ACCESS_KEY') ``` -------------------------------- ### Setup HTML Output and Set Tileset Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Initializes LetsPlot for HTML output and sets a global tileset for maps. Use this to configure the base map appearance. ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() LetsPlot.set(tilesets.LETS_PLOT_LIGHT) ggplot() + geom_livemap() ``` ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() LetsPlot.set(tilesets.LETS_PLOT_BW) ggplot() + geom_livemap() ``` -------------------------------- ### LetsPlot.setup_show_ext Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Configures Lets-Plot to display plots in an external web browser. ```APIDOC ## LetsPlot.setup_show_ext(exec=None, new=False) ### Description Configures Lets-Plot to open HTML output in an external web browser. When enabled, `fig.show()` will generate HTML, save it to a temporary file, and open it in a browser. ### Method `classmethod` ### Endpoint N/A (SDK method) ### Parameters - **exec** (str, optional): The path to an executable to open the HTML file. If not provided, the default system browser is used. The placeholder `%s` can be used to pass the file path. - **new** (bool, default=False): If True, attempts to open the URL in a new browser window. This parameter is only applicable when `exec` is not specified and may not be supported by all browsers or operating systems. ### Request Example ```python # Show the plot in the default web browser. from lets_plot import * LetsPlot.setup_show_ext() p = ggplot() + geom_point(x=0, y=0) p.show() # Show the plot in a new window of the default web browser if possible. LetsPlot.setup_show_ext(new=True) p = ggplot() + geom_point(x=0, y=0) p.show() # Show the plot in Chrome on Windows. LetsPlot.setup_show_ext(exec='C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe --app=%s') p = ggplot() + geom_point(x=0, y=0) p.show() # Show the plot in Safari on macOS. LetsPlot.setup_show_ext(exec='open -a safari %s') p = ggplot() + geom_point(x=0, y=0) p.show() # Show the plot in Chrome on macOS in application mode. LetsPlot.setup_show_ext(exec='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app=%s') p = ggplot() + geom_point(x=0, y=0) p.show() # Show the plot in Chrome on Linux. LetsPlot.setup_show_ext(exec='google-chrome --app=%s') p = ggplot() + geom_point(x=0, y=0) p.show() ``` ### Response None ``` -------------------------------- ### Basic geom_curve Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_curve.html Demonstrates the basic usage of geom_curve to draw a single curved line. Requires LetsPlot setup. ```python from lets_plot import * LetsPlot.setup_html() ggplot() + geom_curve(x=0, y=0, xend=1, yend=0, curvature=0.7, angle=30) ``` -------------------------------- ### LetsPlot.setup_html Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Sets up Lets-Plot to generate HTML output. This is often a prerequisite for displaying plots. ```APIDOC ## LetsPlot.setup_html() ### Description Configures Lets-Plot to generate HTML output for plots. ### Method `classmethod` ### Endpoint N/A (SDK method) ### Parameters None ### Request Example ```python from lets_plot import * LetsPlot.setup_html() ``` ### Response None ``` -------------------------------- ### Apply theme_classic() to a histogram Source: https://lets-plot.org/python/pages/api/lets_plot.theme_classic.html This example demonstrates how to apply the theme_classic() to a ggplot object with a histogram. Ensure Lets-Plot and NumPy are imported, and the HTML setup is complete. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) data = {'x': np.random.normal(size=1000)} ggplot(data, aes(x='x')) + geom_histogram() + \ theme_classic() ``` -------------------------------- ### Basic QQ Plot with Exponential Distribution Source: https://lets-plot.org/python/pages/api/lets_plot.bistro.qq.qq_plot.html This example demonstrates how to create a basic QQ plot comparing sample data to an exponential distribution. It shows how to specify the data, the variable to plot, the theoretical distribution, and customize plot elements like color and line size. ```APIDOC ## qq_plot() ### Description Generates a quantile-quantile plot to compare sample quantiles with theoretical quantiles of a specified distribution. ### Method `qq_plot(data, x, distribution='uniform', **kwargs)` ### Parameters - **data** (dict or DataFrame) - The input data containing the variables to plot. - **x** (str) - The name of the variable in `data` to be plotted on the x-axis (sample quantiles). - **distribution** (str, optional) - The theoretical distribution to compare against. Defaults to 'uniform'. Common options include 'norm', 'exp', 'gamma', 'lnorm', 'unif', 'weibull'. - **quantiles** (list, optional) - A list of quantiles to plot. Defaults to all quantiles. - **color** (str, optional) - Color of the sample quantiles points. - **line_size** (float, optional) - Thickness of the line connecting the sample quantiles. ### Request Example ```python import numpy as np from lets_plot.bistro.qq import qq_plot from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) x = np.random.exponential(1, n) qq_plot({'x': x}, 'x', \ distribution='exp', quantiles=[0, .9], \ color='black', line_size=.25) ``` ### Response #### Success Response (Lets-Plot object) Returns a Lets-Plot object representing the QQ plot. ``` -------------------------------- ### Using scale_fill_cmapmpl with a Matplotlib Colormap Source: https://lets-plot.org/python/pages/api/lets_plot.scale_fill_cmapmpl.html This example demonstrates how to use scale_fill_cmapmpl to create a fill scale with the 'plasma' colormap and custom breaks. Requires matplotlib to be installed. ```python from lets_plot import * LetsPlot.setup_html() x = list(range(50)) ggplot({'x': x}, aes(x='x')) + geom_tile(aes(fill='x')) + scale_fill_cmapmpl('plasma', breaks=[5, 25, 45]) + coord_cartesian() + ggsize(600, 200) ``` -------------------------------- ### Import Libraries and Setup Source: https://lets-plot.org/python/pages/geopandas.html Imports necessary libraries for pandas, Lets-Plot, and geospatial data. Sets up Lets-Plot for HTML output and prepares a sample DataFrame and GeoDataFrame for state boundaries. ```python import pandas as pd from lets_plot.geo_data import * from lets_plot import * LetsPlot.setup_html() df = pd.DataFrame({ 'state': ['IL', 'IN', 'MI', 'OH', 'WI'], 'pop_2021': [12_569_321, 6_805_663, 9_992_427, 11_714_618, 5_852_490], }) gdf = geocode_states(names=df.state).scope('US').get_boundaries()[['state', 'geometry']] ``` -------------------------------- ### Setup External Display - Chrome (macOS) Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Configures Lets-Plot to display plots using Chrome on macOS in application mode. Adjust the path to your Chrome installation if necessary. ```python # Show the plot in the Chrome web browser for macOS in the application mode. # This is the default setup path. Replace the path with your own if it differs. from lets_plot import * LetsPlot.setup_show_ext(exec='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app=%s') p = ggplot() + geom_point(x=0, y=0) p.show() ``` -------------------------------- ### Using LETS_PLOT_LIGHT Tileset in Lets-Plot Source: https://lets-plot.org/python/pages/api/lets_plot.tilesets.LETS_PLOT_LIGHT.html Demonstrates how to set up Lets-Plot for HTML output and use the LETS_PLOT_LIGHT tileset with `geom_livemap` for displaying vector tiles. ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() ggplot() + geom_livemap(tiles=tilesets.LETS_PLOT_LIGHT) ``` -------------------------------- ### Get Country Centroids and Display as Points Source: https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html Fetches the centroid coordinates for specified countries and plots them as points on a map, colored by country name. Requires Lets-Plot setup and imports. ```python from IPython.display import display from lets_plot import * from lets_plot.geo_data import * LetsPlot.setup_html() countries = geocode_countries(['Germany', 'Poland']).get_centroids() display(countries) ggplot() + geom_point(aes(color='found name'), data=countries, size=10) ``` -------------------------------- ### Gradient Color Scale for geom_tile Source: https://lets-plot.org/python/pages/api/lets_plot.scale_color_gradient.html This example demonstrates how to use scale_color_gradient to create a smooth color gradient for the 'x' aesthetic in a geom_tile plot. It specifies the low and high colors and sets the guide to 'legend'. ```python from lets_plot import * LetsPlot.setup_html() x = list(range(50)) ggplot({'x': x}, aes(x='x')) + \ geom_tile(aes(color='x'), fill='white', size=3) + \ scale_color_gradient(low='#1a9641', high='#d7191c', guide='legend') + \ coord_cartesian() + \ ggsize(600, 200) ``` -------------------------------- ### Lets-Plot ggplot Initialization and Layering Source: https://lets-plot.org/python/pages/api/lets_plot.ggplot.html Demonstrates three ways to initialize a ggplot object and add a geom_point layer. This covers scenarios where data and aesthetics are defined upfront, data is defined upfront with aesthetics in the layer, or neither are defined upfront. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) n = 100 x = np.random.uniform(-1, 1, size=n) y = np.random.normal(size=n) data = {'x': x, 'y': 25 * x ** 2 + y} # three ways to invoke ggplot, producing the same output: # (1) ggplot(data, aes(x='x', y='y')) + geom_point() # (2) ggplot(data) + geom_point(aes(x='x', y='y')) # (3) ggplot() + geom_point(aes(x='x', y='y'), data=data) ``` -------------------------------- ### Use CARTO_POSITRON_HIRES Tileset Source: https://lets-plot.org/python/pages/api/lets_plot.tilesets.CARTO_POSITRON.html Displays a live map using the high-resolution CARTO_POSITRON_HIRES tileset. Requires LetsPlot HTML setup. ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() ggplot() + geom_livemap(tiles=tilesets.CARTO_POSITRON_HIRES) ``` -------------------------------- ### scale_fill_grey Source: https://lets-plot.org/python/pages/api/lets_plot.scale_fill_grey.html Creates a sequential grey color scale for the 'fill' aesthetic. This function allows customization of the color palette by specifying the start and end gray values, as well as controlling the appearance of the guide and labels. ```APIDOC ## scale_fill_grey() ### Description Sequential grey color scale for `fill` aesthetic. ### Parameters - **start** (float) - Gray value at low end of palette in range [0, 1]. - **end** (float) - Gray value at high end of palette in range [0, 1]. - **name** (str) - The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic. - **breaks** (list or dict) - A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values. - **labels** (list of str or dict) - A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels. - **lablim** (int, default=None) - The maximum label length (in characters) before trimming is applied. - **limits** (list) - Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale and the default order of their display in guides. - **na_value** - Missing values will be replaced with this value. - **guide** - Guide to use for this scale. It can either be a string (‘colorbar’, ‘legend’) or a call to a guide function (guide_colorbar(), guide_legend()) specifying additional arguments. ‘none’ will hide the guide. - **trans** ({'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}) - Name of built-in transformation. - **format** (str) - Define the format for labels on the scale. The syntax resembles Python’s: * '.2f' -> '12.45' * 'Num {}' -> 'Num 12.456789' * 'TTL: {.2f}$' -> 'TTL: 12.45$' ### Returns - `FeatureSpec` - Scale specification. ### Notes Define sequential grey color scale for `fill` aesthetic. Use the `palette(n)` method to generate a list of n colors from this scale. ### Example ```python from lets_plot import * LetsPlot.setup_html() x = list(range(50)) ggplot({'x': x}, aes(x='x')) + \ geom_tile(aes(fill='x')) + \ scale_fill_grey(start=.9, end=.1) + \ coord_cartesian() + \ ggsize(600, 200) ``` ``` -------------------------------- ### Advanced LetsPlot HTML Setup with Options Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Configures Lets-Plot HTML output with specific options for isolated frames, offline mode, static SVG, and status display. Use this when custom configurations are needed for internet connectivity or output format. ```python from lets_plot import * LetsPlot.setup_html(isolated_frame=False, offline=True, \ no_js=True, show_status=True) ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point() ``` -------------------------------- ### Sequential Grey Color Scale Example Source: https://lets-plot.org/python/pages/api/lets_plot.scale_fill_grey.html Demonstrates how to use scale_fill_grey to apply a sequential grey color scale to a geom_tile plot. The start and end parameters control the range of grey values used. ```python from lets_plot import * LetsPlot.setup_html() x = list(range(50)) ggplot({'x': x}, aes(x='x')) + \ geom_tile(aes(fill='x')) + \ scale_fill_grey(start=.9, end=.1) + \ coord_cartesian() + \ ggsize(600, 200) ``` -------------------------------- ### Sequential Grey Color Scale Example Source: https://lets-plot.org/python/pages/api/lets_plot.scale_color_grey.html Demonstrates the use of scale_color_grey to create a sequential grey color scale for a geom_tile plot. The start and end parameters control the range of grey values used in the scale. ```python from lets_plot import * LetsPlot.setup_html() x = list(range(50)) ggplot({'x': x}, aes(x='x')) + \ geom_tile(aes(color='x'), fill='white', size=3) + \ scale_color_grey(start=.7, end=.2) + \ coord_cartesian() + \ ggsize(600, 200) ``` -------------------------------- ### Combined Date and Time Format Examples Source: https://lets-plot.org/python/pages/formats.html Illustrates various combinations of date and time formatting directives to create custom output strings for specific use cases. ```text %Y-%m-%dT%H:%M:%S.%f --> "2019-08-06T04:46:35.123" %m/%d/%Y --> "08/06/2019" %m-%d-%Y %H:%M --> "08-06-2019 04:46" %d.%m.%y --> "06.08.19" %A, %b %e, %Y --> "Tuesday, Aug 6, 2019" %b %d, %l:%M %p --> "Aug 06, 4:46 AM" %B %Y --> "August 2019" %b %e, %Y --> "Aug 6, 2019" %a, %e %b %Y %H:%M:%S --> "Tue, 6 Aug 2019 04:46:35" %B %e %Y %H:%M %p --> "August 6 2019 04:46 AM" ``` -------------------------------- ### Using scale_cmapmpl with geom_tile Source: https://lets-plot.org/python/pages/api/lets_plot.scale_cmapmpl.html This example demonstrates how to use scale_cmapmpl to apply a 'plasma' colormap to both 'color' and 'fill' aesthetics for geom_tile. It also sets custom breaks for the color scale. Ensure matplotlib is installed for this function to work. ```python from lets_plot import * LetsPlot.setup_html() x = list(range(50)) ggplot({'x': x}, aes(x='x')) + \ geom_tile(aes(color='x', fill='x')) + \ scale_cmapmpl(aesthetic=['color', 'fill'], cmap='plasma', breaks=[5, 25, 45]) + \ coord_cartesian() + \ ggsize(600, 200) ``` -------------------------------- ### Create Solid Color Map Tiles with Lets-Plot Source: https://lets-plot.org/python/pages/api/lets_plot.maptiles_solid.html Demonstrates how to create solid color map tiles using maptiles_solid and apply them to a livemap visualization. Requires Lets-Plot setup and geo_data for map content. ```python from lets_plot import * from lets_plot.geo_data import * LetsPlot.setup_html() yc = geocode_cities('New York').get_boundaries() tiles = maptiles_solid(color='#d3d3d3') ggplot() + geom_livemap(tiles=tiles) + geom_map(data=nyc) ``` -------------------------------- ### Create a Pie Chart with Tooltips Source: https://lets-plot.org/python/pages/api/lets_plot.geom_pie.html This example demonstrates how to create a pie chart on a live map using geom_pie. It configures detailed tooltips to show city, population by sex, and total population, with specific formatting for numbers. ```python from lets_plot import * from lets_plot.geo_data import * LetsPlot.setup_html() data = {"city": ["New York", "New York", "Philadelphia", "Philadelphia"], "est_pop_2020": [4_381_593, 3_997_959, 832_685, 748_846], "sex": ["female", "male", "female", "male"]} centroids = geocode_cities(data["city"]).get_centroids() ggplot() + geom_livemap() + \ geom_pie(aes(fill="sex", weight="est_pop_2020", size="..sum..", group=["city", "sex"]), data=data, map=centroids, map_join="city", tooltips=layer_tooltips().title("@city") .format("@est_pop_2020", ".3~s") .line("population (@sex):\n@est_pop_2020 (@..proppct..)") .format("@..sum..", ".3~s") .line("population (total):\n@..sum..")) + \ scale_size(range=[4, 10], guide='none') ``` -------------------------------- ### Scale Guides Source: https://lets-plot.org/python/pages/api.html Functions to configure guides for scales, such as legends and color bars. ```APIDOC ## guide_legend ### Description Legend guide. ### Method N/A (Function call) ### Endpoint N/A ## guide_colorbar ### Description Continuous color bar guide. ### Method N/A (Function call) ### Endpoint N/A ## guides ### Description Set guides for each scale. ### Method N/A (Function call) ### Endpoint N/A ## layer_key ### Description Configure custom legend. ### Method N/A (Function call) ### Endpoint N/A ``` -------------------------------- ### Using NASA CityLights 2012 Tileset in Lets-Plot Source: https://lets-plot.org/python/pages/api/lets_plot.tilesets.NASA_CITYLIGHTS_2012.html Demonstrates how to import necessary Lets-Plot modules and use the NASA_CITYLIGHTS_2012 tileset with geom_livemap for displaying city lights data. ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() ggplot() + geom_livemap(tiles=tilesets.NASA_CITYLIGHTS_2012) ``` -------------------------------- ### Using LETS_PLOT_DARK Tileset Source: https://lets-plot.org/python/pages/api/lets_plot.tilesets.LETS_PLOT_DARK.html Demonstrates how to import necessary Lets-Plot modules and use the LETS_PLOT_DARK tileset with geom_livemap. Ensure LetsPlot.setup_html() is called before plotting. ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() ggplot() + geom_livemap(tiles=tilesets.LETS_PLOT_DARK) ``` -------------------------------- ### guides() Source: https://lets-plot.org/python/pages/api/lets_plot.guides.html Set guides for each scale. This function allows customization of how legends and colorbars are displayed for different aesthetics. ```APIDOC ## guides() ### Description Set guides for each scale. This function allows customization of how legends and colorbars are displayed for different aesthetics. ### Parameters * **kwargs**: Key-value pairs where the key can be an aesthetic name, 'manual' for a default custom legend, or a group name for a custom legend defined via `layer_key()`. The value can be a string ('colorbar', 'legend'), a call to a guide function (e.g., `guide_colorbar()`, `guide_legend()`) with additional arguments, or 'none' to hide the guide. ### Returns * `FeatureSpec`: Guides specification. ``` -------------------------------- ### Example Palette Output Source: https://lets-plot.org/python/pages/api/lets_plot.plot.core.ColorScaleFeatureSpec.palette.html Shows the expected output format for the `palette` method when requesting 5 colors from the viridis scale. ```json ["#440154", "#3b528b", "#21918d", "#5dc863", "#fde725"] ``` -------------------------------- ### Basic geom_area_ridges Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_area_ridges.html A basic example demonstrating the usage of geom_area_ridges with default settings. Requires numpy and lets_plot libraries. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() n, m = 10, 3 np.random.seed(42) x = np.random.normal(size=n*m) y = np.repeat(np.arange(m), n) ggplot({'x': x, 'y': y}, aes('x', 'y')) + \ geom_area_ridges() ``` -------------------------------- ### LetsPlot.setup_html Source: https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html Configures Lets-Plot HTML output. This method should typically be called before rendering any plots. It allows for customization of the HTML output mode, including options for iframe compatibility, offline usage, and static SVG generation. ```APIDOC ## LetsPlot.setup_html ### Description Configures Lets-Plot HTML output. This method should typically be called before rendering any plots. Depending on the usage, Lets-Plot generates different HTML to show plots. In most cases Lets-Plot will detect the type of the environment automatically. Use this method to adjust or override the autoconfigured output mode. ### Method classmethod ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **isolated_frame** (bool) - True - generate HTML which can be used in iframe or in a standalone HTML document. False - preload Lets-Plot JS library. Notebook cell output will only consist of HTML for the plot rendering. Default: auto-detect. - **offline** (bool) - True - full Lets-Plot JS bundle will be added to the notebook. Use this option if you would like to work with a notebook without the Internet connection. False - load Lets-Plot JS library from CDN. Default: ‘connected’ mode in the production environment, ‘offline’ mode in the dev environment. - **no_js** (bool, default=False) - True - do not generate HTML+JS as an output - just static SVG image. Note that without JS interactive maps and tooltips don’t work! - **show_status** (bool, default=False) - Whether to show the Lets-Plot JS library loading status. Only applicable when the Lets-Plot JS library is preloaded. - **kwargs** - Advanced display options for developers testing in new environments or debugging rendering behavior. These options control the underlying HTML rendering: - **isolated_webview_panel** (bool) - If True, generates HTML for an isolated webview panel with dynamic script loading. When enabled, the ‘isolated_frame’ parameter is ignored. - **width_mode** (str) - Plot width sizing mode: ‘fixed’, ‘min’, ‘fit’, or ‘scaled’. Requires height_mode to also be specified. - **height_mode** (str) - Plot height sizing mode: ‘fixed’, ‘min’, ‘fit’, or ‘scaled’. Requires width_mode to also be specified. - **width** (float) - Explicit width value in px (used with certain sizing modes). - **height** (float) - Explicit height value in px (used with certain sizing modes). - **force_immediate_render** (bool) - Controls the timing of plot rendering. If True, renders plot immediately. If False, waits for the ResizeObserver event to ensure proper DOM layout. - **responsive** (bool) - If True, the plot automatically resizes when the container is resized. - **height100pct** (bool) - If True, sets the plot container div height to 100%. Sizing modes: - ‘fixed’: Uses specified width/height or default size (not responsive) - ‘min’: Uses smallest of: default size, specified size, and container size - ‘fit’: Uses container size or specified size if provided - ‘scaled’: Adjusts to preserve the aspect ratio ### Request Example ```python from lets_plot import * LetsPlot.setup_html() ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point() ``` ```python from lets_plot import * LetsPlot.setup_html(isolated_frame=False, offline=True, \ no_js=True, show_status=True) ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point() ``` ### Response #### Success Response (200) None explicitly documented. #### Response Example None explicitly documented. ``` -------------------------------- ### Apply High-Contrast Light Theme to a Pie Chart Source: https://lets-plot.org/python/pages/api/lets_plot.flavor_high_contrast_light.html This example demonstrates how to use flavor_high_contrast_light() to set a high-contrast light theme for a pie chart created with Lets-Plot. Ensure LetsPlot is set up for HTML output. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() data = {'name': ['pen', 'brush', 'paper'], 'slice': [1, 3, 3]} ggplot(data) + \ geom_pie(aes(fill='name', slice='slice'), stat='identity', color='pen', tooltips='none', labels=layer_labels().line('@name')) + \ scale_fill_manual(['pen', 'brush', 'paper']) + \ flavor_high_contrast_light() ``` -------------------------------- ### Basic geom_dotplot Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_dotplot.html A simple example demonstrating the default usage of geom_dotplot with normally distributed data. Requires numpy and lets_plot imports. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) data = {'x': np.random.normal(size=100)} ggplot(data, aes(x='x')) + geom_dotplot() ``` -------------------------------- ### LetsPlot Initialization Source: https://lets-plot.org/python/pages/api.html Initialize the Lets-Plot library and configure its options. ```APIDOC ## LetsPlot ### Description Initialize the library and its options. ### Method N/A (Function call) ### Endpoint N/A (Library function) ### Parameters N/A ``` -------------------------------- ### Basic geom_ydotplot Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_ydotplot.html A simple example of using geom_ydotplot to create a dot plot. This requires importing Lets-Plot and numpy, and setting up the HTML environment. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) n = 100 x = np.random.choice(['A', 'B'], size=n) y = np.random.normal(size=n) ggplot({'x': x, 'y': y}, aes('x', 'y')) + geom_ydotplot() ``` -------------------------------- ### Use CARTO_POSITRON Tileset Source: https://lets-plot.org/python/pages/api/lets_plot.tilesets.CARTO_POSITRON.html Displays a live map using the standard CARTO_POSITRON tileset. Ensure LetsPlot is set up for HTML output. ```python from lets_plot import * from lets_plot import tilesets LetsPlot.setup_html() ggplot() + geom_livemap(tiles=tilesets.CARTO_POSITRON) ``` -------------------------------- ### Basic geom_ribbon Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_ribbon.html A simple example demonstrating the basic usage of geom_ribbon to display a y interval defined by ymin and ymax. Requires numpy and lets_plot libraries. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() n = 10 np.random.seed(42) x = np.arange(n) ymin = np.random.randint(-5, 0, size=n) ymax = np.random.randint(1, 6, size=n) ggplot({'x': x, 'ymin': ymin, 'ymax': ymax}, aes(x='x')) + geom_ribbon(aes(ymin='ymin', ymax='ymax')) ``` -------------------------------- ### Layer Labels with Multiple Formats and Lines Source: https://lets-plot.org/python/pages/api/lets_plot.layer_labels.html Demonstrates configuring multiple lines of annotation with custom formatting for variables and aesthetics. This example shows how to chain format and line methods. ```python from lets_plot import * LetsPlot.setup_html() layer_labels().format('@{..prop..}', '.0%') \ .line('@name') \ .line('(@{..prop..})') \ .as_dict() ``` -------------------------------- ### Basic geom_bin2d Example Source: https://lets-plot.org/python/pages/api/lets_plot.geom_bin2d.html This example demonstrates the basic usage of geom_bin2d to create a 2D histogram from multivariate normal data. It requires importing numpy and lets_plot libraries. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) mean = np.zeros(2) cov = np.eye(2) x, y = np.random.multivariate_normal(mean, cov, 1000).T ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + geom_bin2d() ``` -------------------------------- ### Diverging Color Gradient Example Source: https://lets-plot.org/python/pages/api/lets_plot.scale_fill_gradient2.html This example demonstrates how to use scale_fill_gradient2 to create a diverging color scale for a geom_tile plot. It sets custom low, mid, and high colors. ```python from lets_plot import * LetsPlot.setup_html() x = list(range(-25, 26)) ggplot({'x': x}, aes(x='x')) + \ geom_tile(aes(fill='x')) + \ scale_fill_gradient2(low='#2b83ba', mid='#ffffbf', high='#d7191c') + \ coord_cartesian() + \ ggsize(600, 200) ``` -------------------------------- ### Create a Grid of Plots Source: https://lets-plot.org/python/pages/api/lets_plot.gggrid.html This example demonstrates how to create a grid of plots using `gggrid`. It defines a list of plot specifications and arranges them in a single column. ```python import numpy as np from lets_plot import * LetsPlot.setup_html() np.random.seed(42) n = 100 x = np.arange(n) y = np.random.normal(size=n) w, h = 200, 150 p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h) plot_list=[ gggrid([p+geom_point(), p+geom_histogram(bins=3)]), p+geom_line() ] gggrid(plot_list, ncol=1) + ggsize(400, 300) ```