Plot#

property Series.plot: SeriesPlot[source]#

Create a plot namespace.

Warning

This functionality is currently considered unstable. It may be changed at any point without it being considered a breaking change.

Changed in version 1.6.0: In prior versions of Polars, HvPlot was the plotting backend. If you would like to restore the previous plotting functionality, all you need to do is add import hvplot.polars at the top of your script and replace df.plot with df.hvplot.

Polars does not implement plotting logic itself, but instead defers to Altair:

  • s.plot.hist(**kwargs) is shorthand for alt.Chart(s.to_frame()).mark_bar(tooltip=True).encode(x=alt.X(f'{s.name}:Q', bin=True), y='count()', **kwargs).interactive()

  • s.plot.kde(**kwargs) is shorthand for alt.Chart(s.to_frame()).transform_density(s.name, as_=[s.name, 'density']).mark_area(tooltip=True).encode(x=s.name, y='density:Q', **kwargs).interactive()

  • for any other attribute attr, s.plot.attr(**kwargs) is shorthand for alt.Chart(s.to_frame().with_row_index()).mark_attr(tooltip=True).encode(x='index', y=s.name, **kwargs).interactive()

Examples

Histogram:

>>> s = pl.Series([1, 4, 4, 6, 2, 4, 3, 5, 5, 7, 1])
>>> s.plot.hist()  

KDE plot:

>>> s.plot.kde()  

Line plot:

>>> s.plot.line()