I have a stripplot where I use binned data for the coloration of the datapoints. Instead of a legend I'd like to show a colorbar. I've looked at many examples but I'm stuck at how to use this with a Seaborn Stripplot (and my dataset).
I have a dataframe dfBalance which has numerical data in column Balance and the different categories in column Parameter. It also contains time in a column Time which I use for binning for coloration of the datapoints
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame([[40, 'A',65], [-10, 'A',125], [60, 'B',65], [5, 'B',135], [8, 'B',205], [14, 'B',335]], columns=['Balance', 'Parameter', 'Time'])
bin = np.arange(0,max(df['Time']),60)
df['bin'] = pd.cut(abs(df['Time']),bin,precision=0)
plt.figure()
cpal=sns.color_palette('cmo.balance',n_colors=28,desat=0.8)
plt.style.use("seaborn-dark")
ax = sns.stripplot(x='Balance', y='Parameter', data=df, jitter=0.15, edgecolor='none', alpha=0.4, size=4, hue='bin', palette=cpal)
sns.despine()
ax.set_xlim([-45,45])
plt.title("L/R Balance")
plt.xlabel("Balance % L/R")
plt.ylabel("Parameter")
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
plt.legend(loc=1)
plt.show()
This produces a plot as follows:
Is there any way to replace the legend with a colorbar?