---
title: "Custom Python plots in Vista | Oplema"
description: "Draw a custom Matplotlib plot in Vista with Python, reading one source as a Polars DataFrame, for charts the built-in visuals don't cover."
url: "https://oplema.com/docs/vista/developer/python"
updated: "2026-11-04"
---

# Python

Python draws a plot with your own code. It reads one Vista source as input\_1, a Polars DataFrame. After you edit the code, select Run to redraw it.

## Draw a bar plot with Python

The default script reads Tea, Coffee and Cocoa from input\_1 and draws them with matplotlib's plt.bar. The first plot takes a while, because the Python runtime has to load in your browser.

Result
| Drink | Cups |
| --- | --- |
| Tea | 20 |
| Coffee | 30 |
| Cocoa | 10 |

1. Wait for the plot to appear. Current below the code editor means the plot reflects your code.
2. In the code editor, find `plt.bar(labels, values)` and change it, for example the labels or the color.
3. Select Run. The plot redraws. Editing alone doesn't run the code.

## When to use

Use Python when no built-in chart can draw what you need and you know matplotlib and Polars. Built-in charts load faster and need no code, so try the palette first. If your team already writes its plots in base R, use R.

## Inputs

1 port

**Data source**

Accepts: Tables.

Accepts one connection on this port.

## Settings

**Python**

Python plot code. Edit it in the Python editor in Properties.

Default: `import matplotlib.pyplot as plt # Choose the label and value columns from your source. label_column, value_column = input_1.columns[:2] labels = input_1[label_column].to_list() values = input_1[value_column].cast(float).to_list() plt.bar(labels, values) plt.xlabel(label_column) plt.ylabel(value_column) plt.title(f"{value_column} by {label_column}") plt.tight_layout()`

**Corner radius (px)**

Corner radius in whole logical pixels.

Default: `0`

**Border width (px)**

Border width in whole logical pixels.

Default: `0`

## Python FAQs

**Does editing run the code automatically?**

No. Select Run. History and Elara previews don't execute code.

**Can I install packages?**

Use the bundled libraries only.

**Why does the footer say Sampled source preview?**

The editor shows this label on every plot while the preview uses a row limit. At All rows it disappears. See Your first dashboard for how previews and published dashboards use rows.

### Chart your data. Build it in Vista.

Vista opens in your browser, with no account.

[Open Vista](https://oplema.com/editor?path=%2F%3Fopen%3Dvista) [About Vista](https://oplema.com/vista)
