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.
Python interactive example
Loading interactive example…
The live example needs a desktop screen. The result it produces is shown here, and the explanation and settings below work on any screen.
| Drink | Cups |
|---|---|
| Tea | 20 |
| Coffee | 30 |
| Cocoa | 10 |
- Wait for the plot to appear. Current below the code editor means the plot reflects your code.
- In the code editor, find
plt.bar(labels, values)and change it, for example the labels or the color. - 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
- 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.