Using the latest version of plotly=6.1.2
and plotly.express=1.30.0
, I was able to just remove the to_pandas()
and your code just worked as is. This is because plotly
, natively support polars now.
import plotly.express as px
import polars as pl
tidy_df_pl = pl.DataFrame(
{
"x": [10, 10, 10, 20, 20, 20, 30, 30, 30],
"y": [3, 4, 5, 3, 4, 5, 3, 4, 5],
"value": [5, 8, 2, 4, 10, 14, 10, 8, 9],
}
)
print(tidy_df_pl)
pivot_df_pl = (
tidy_df_pl.pivot(index="x", on="y", values="value")
)
print(pivot_df_pl)
fig = px.imshow(pivot_df_pl)
fig.show()
As an alternative, you can also plot the heatmap with seaborn=0.13.2
, which also supports polars
now.
import seaborn as sns
sns.heatmap(pivot_df_pl, annot=True)