In addition to interactive, no-code Plot cell, Latch Plots allows developers to programmatically use any library and generate plots of interest.

There are two main ways to programmatically create custom plots:

  1. Display an image using libraries like seaborn or matplotlib

  2. Display a figure from plotly

Option 1: Display a plot image from seaborn or matplotlib

Step 1: Install the Python packages

To install your Python libraries, first click on Custom Data Analysis to create a Python cell. Paste in the following Python code to install packages:

import os

os.system("/opt/mamba/envs/plots-faas/bin/pip install matplotlib")

Step 2: Display the plot as an image

To display a matplotlib or seaborn figure, first assign the figure to a variable, e.g. fig

import pandas as pd
import matplotlib.pyplot as plt

# Load the dataset
df = pd.read_csv("https://latch-public.s3.us-west-2.amazonaws.com/plots/test-data/iris.csv")

# Create the scatter plot
plt.figure(figsize=(10, 6))

print(df)

# Store the matplotlib figure in a `fig`variable
fig = plt.scatter(df['sepal.length'], df['sepal.width'], c='blue', label='Sepal')
plt.scatter(df['petal.length'], df['petal.width'], c='green', label='Petal')

Click on the fig variable to display the image in the output of the cell.

Option 2: Display a custom, interactive Plotly figure

First, click on Custom Data Analysis to create a new Python cell. Next, import the Plotly Express library and create your plot of interest.

In the example below, we created a scatter plot for the iris dataset, and save the Plotly object as a Python variable called fig.

import plotly.express as px

df = px.data.iris()

fig = px.scatter(
  df,
  x="sepal_length",
  y="sepal_width",
  template="simple_white"
)

Select the fig variable to display the interactive Plotly figure in the output of the cell.