LoginSignup
3
1

Polars の `DataFrame.plot` を Google Colaboratory で動かす

Last updated at Posted at 2024-01-23

Polars 0.20.3DataFrame.plot が追加されました 🎉

2024-01-23現在、Google Colaboratory で動かすには細工が必要だったのでメモを残します。
これをやらないと一回目の DataFrame.plot ではグラフが表示されるのに二回目は表示されないです。

コード

%pip -q install -U hvplot holoviews

def _render(self, **kwargs):
    # https://github.com/holoviz/holoviews/issues/3551#issuecomment-578394636
    import holoviews as hv
    hv.extension("bokeh")  # type: ignore
    return hv.Store.render(self)

__import__("holoviews").core.Dimensioned._repr_mimebundle_ = _render
%pip -q install -U polars[numpy,plot]
import numpy as np
import polars as pl

df = (
    pl.DataFrame({"x": np.linspace(0, 2 * np.pi)})
    .with_columns(
        y=np.sin(pl.col("x")),
        日本語も使える=np.cos(pl.col("x"))
    )
)

df.plot(x="x", y=["y", "日本語も使える"], subplots=True).cols(1)

bokeh_plot.png

なんでなん

セキュリティ上の都合ならしゃーない

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1