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()

For configuration, we suggest reading Chart Configuration. For example, you can:

  • Change the width/height/title with .properties(width=500, height=350, title="My amazing plot").

  • Change the x-axis label rotation with .configure_axisX(labelAngle=30).

  • Change the opacity of the points in your scatter plot with .configure_point(opacity=.5).

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()