Polars is fast, expressive, and increasingly the go-to DataFrame library for Python. But it does not ship with a plotting API. If you want a chart, you need to hand the data off to a visualisation library at the boundary.
This is by design. The Polars team recommends keeping data processing inside Polars and converting to pandas (or extracting lists and arrays) only when you need to plot. This tutorial walks through three ways to do exactly that:
- matplotlib
axes.plot()— extract columns with.to_list()and plot manually - pandas
DataFrame.plot()— convert to pandas first, then use the familiar.plot()API - seaborn
lineplot()— pass long-form pandas data and let seaborn handle grouping
Every example uses the same dataset — monthly EV vs Diesel car registrations — so you can compare the three approaches side by side.
Step 1 — Create the dataset
We start with a long-form DataFrame where each row is one monthly observation for a vehicle type. We then pivot it to wide form, which some plotting methods prefer. Run the block below to create both versions.
The long-form table (cars) has 12 rows — six months for EV and six for Diesel. The wide-form table (cars_wide) has six rows with separate EV and Diesel columns. Some plotting libraries prefer one shape over the other, which is why we create both.
Method 1 — matplotlib axes.plot()
The most explicit approach: extract each Polars column as a Python list using .to_list(), then pass the lists to matplotlib. This keeps Polars and matplotlib completely separate — no pandas conversion needed.
When to use this method: When you want full control over every element of the chart — colours, markers, annotations, subplots. It is verbose but completely transparent.
The key line is cars_wide["EV"].to_list(). Polars columns are not directly accepted by matplotlib, so you convert at the boundary. You could also use .to_numpy() if you prefer arrays.
Method 2 — pandas DataFrame.plot()
If you want a quick chart with minimal code, convert the Polars DataFrame to pandas and call .plot(). This works because pandas DataFrames have a built-in plotting API powered by matplotlib — Polars does not.
When to use this method: When you want a chart fast and do not need fine-grained control. One line — cars_wide.to_pandas().plot(x="month", y=["EV","Diesel"]) — gives you a multi-series line chart with an automatic legend.
The conversion cost of .to_pandas() is negligible for small to medium datasets. For very large frames (millions of rows), consider downsampling in Polars first.
Method 3 — seaborn lineplot()
Seaborn shines with long-form (tidy) data. Pass the original cars DataFrame — converted to pandas — and use the hue parameter to split lines by vehicle type. Seaborn handles colours, legends, and grouping automatically.
When to use this method: When your data is already in long (tidy) form and you want automatic grouping. Seaborn is ideal for exploratory analysis where you want to quickly split by a categorical variable.
Comparison — which method when?
All three methods produce the same chart. The difference is in how much control you want versus how much code you want to write:
- matplotlib
axes.plot()— Maximum control. You extract lists or arrays from Polars and build every element manually. Best for publication-quality figures, subplots, and custom annotations. - pandas
DataFrame.plot()— Minimum code. Convert to pandas with.to_pandas()and call.plot(). Best for quick exploration when you already know the wide-form shape you want. - seaborn — Best for long-form data. Automatic colour-coding and legends via
hue. Best for exploratory analysis with categorical splits, statistical plots (boxplots, violins, histograms), and when your data is already tidy.
The underlying principle is the same in all three cases: Polars handles data processing; for plotting, convert to pandas or numpy at the boundary. This is the recommended Polars workflow. Keep your transformations — filtering, grouping, joining — in Polars for speed and expressiveness, then hand off the final result to a visualisation library at the last step.
Try editing the code blocks above — change colours, swap lineplot for barplot, or add more months to the dataset. Each block runs independently in the browser.
References
- Polars documentation: polars.DataFrame.to_pandas
- Polars documentation: polars.Series.to_list
- Matplotlib documentation: Axes.plot
- Seaborn documentation: seaborn.lineplot
- Related tutorial: How to Create a Graph in Python