Polars is a blazing-fast DataFrame library, but unlike pandas it does not ship with a built-in .plot() method. That is a deliberate design choice — Polars focuses on data manipulation, and leaves visualisation to dedicated libraries like matplotlib, plotly, or altair.

The good news: connecting Polars to matplotlib is straightforward. You extract a column as a Python list or NumPy array, then pass it to any matplotlib function. This article walks through the full workflow using a dataset of EV vs Diesel car registrations:

  1. Create a Polars DataFrame with long-form data
  2. Pivot the data to wide form for easy plotting
  3. Draw a simple single-series line chart
  4. Plot two series on the same axes
  5. Polish the chart with labels, legend, grid, and title

The dataset

We will use a dataset tracking monthly new-car registrations (in thousands) for electric vehicles (EV) and diesel cars across a single calendar year. The EV column trends upward as adoption accelerates, while diesel registrations decline — a pattern seen in many markets worldwide.

Python — editable
Figure 1: EV and Diesel registrations in long form — 24 rows, 3 columns.

The data is in long form: each row is one vehicle type in one month. This is great for filtering and aggregation, but for plotting we usually want wide form — one column per series. Polars makes this easy with .pivot().

Pivot to wide form

The .pivot() method reshapes the DataFrame so that each unique value in the on column becomes its own column. We keep month as the index (row identifier) and spread monthly_registrations across the vehicle types:

Python — editable
Figure 2: Wide form — one column per vehicle type.

Now we have a clean 12-row DataFrame with columns month, EV, and Diesel. Each column can be extracted directly and passed to matplotlib.

A simple line plot

To plot a Polars column with matplotlib, convert it to a list using .to_list() (or a NumPy array using .to_numpy()). Here is the simplest possible line chart — just the EV registrations over the year:

Python — editable
Figure 3: A minimal line chart of EV registrations.

Three things to note:

Plotting two series

Adding a second series is as simple as calling ax.plot() again on the same axes. Let's overlay the diesel registrations alongside the EV data:

Python — editable
Figure 4: EV vs Diesel registrations on the same chart.

The crossover point — where EV registrations surpass diesel — is immediately visible. We added label= to each ax.plot() call and then ax.legend() to display the legend. The chart works, but it could use some polish.

A polished chart

Let's add axis labels, a title, grid lines, custom y-axis limits, and a tighter layout to produce a publication-ready chart:

Python — editable
Figure 5: A polished line chart with labels, legend, grid, and title.

Key additions:

Try editing the code blocks above — change marker styles, swap colours, adjust figsize, or plot a bar chart with ax.bar() instead of ax.plot().

Polars vs pandas: plotting compared

If you are coming from pandas, here is how the plotting workflow differs:

The extra step of extracting columns with .to_list() is minimal, and you gain full control over the matplotlib API rather than relying on pandas' convenience wrapper.

References

Suhith Illesinghe
Curiosity is the first step to make a difference. I hope to inspire others to explore, build and champion collaborative growth.