How to get something like sns.barplot for df.hvplot.explorer()

Firstly, Love hvplot.explorer(). I love that it’s like a drop in BI tool in a jupyter notebook.

I’m curious how to use to generate a plot like

sns.barplot(x="Pclass", y="Survived", data=df)

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style="whitegrid")
plt.figure(figsize=(10, 6))
sns.barplot(x="Pclass", y="Survived", data=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv"))
plt.title("Survival Rate by Passenger Class")
plt.xlabel("Passenger Class")
plt.ylabel("Survival Rate")
plt.show()

I’m not too worried about the error bars.

The matplotlib plot code would be

import pandas as pd
import matplotlib.pyplot as plt

survival_rates = pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv").groupby('Pclass')['Survived'].mean()

plt.figure(figsize=(10, 6))
plt.bar(survival_rates.index, survival_rates.values)
plt.title("Survival Rate by Passenger Class")
plt.xlabel("Passenger Class")
plt.ylabel("Survival Rate")
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()

In the hvplot.explorer i’m looking how to do agg: mean and also plot all the classes on the x axis instead of a slider

import pandas as pd
import hvplot.pandas

df = pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")
hvexplorer = df.hvplot.explorer()
hvexplorer

Set groupby=[] or ctrl+click Pclass in the UI.

Sorry not following.

Doing “ctrl+click Pclass in the UI” brings up jupyter options. Did you mean command+click? (i’m on a mac).

Not sure how to “Set groupby=[]” either.

Ah sorry, now I see that you do an average; I don’t think hvplot supports operations like that out of the box. Lumen does though Transport for London: Bike Point Occupancy — Lumen 1.5.0b1 documentation

You’d probably have to do it like how you did for matplotlib.