I have a dataframe, from which I take several data-groups and display as a displot on the same figure (overlayed). I also display a table summarizing some data regarding each group. I would like to display each row in the table (=each group) in the same color as the matching displot color. I've tried to define a common colormap to both the table and the displot, however the displot throws an error:
in distplot
if kde_color != color:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Process finished with exit code 1
Here is the code:
fig, (ax_plot, ax_table) = plt.subplots(nrows=2, figsize=(11.69, 8.27),
gridspec_kw=dict(height_ratios=[3, 1]) )
ax_table.axis("off")
item_types = item_df['item_type'].unique()
columns = ('item type', 'Average DR', 'Percent DR passed 50%', 'Percent DR passed 60%', 'Percent DR passed 70%',
'Percent DR passed 80%')
cell_text = []
table_colors = plt.cm.BuPu(np.linspace(0, 0.5, len(item_types)))
i=0
for item_type in item_types:
item_dr = item_df[item_df['item_type'] == item_type]['interesting_feature'].values
color = table_colors[i, 0:3]
sns.distplot(item_dr, hist=False, label=item_type, ax=ax_plot, color=mcolors.rgb_to_hsv(color))
i += 1
avg_dr = np.mean(item_dr)
pass50 = len(item_dr[item_dr > 0.5]) / len(item_dr)
pass60 = len(item_dr[item_dr > 0.6]) / len(item_dr)
pass70 = len(item_dr[item_dr > 0.7]) / len(item_dr)
pass80 = len(item_dr[item_dr > 0.8]) / len(item_dr)
cell_text.append([str(item_type), str(avg_dr), str(pass50), str(pass60), str(pass70), str(pass80)])
item_table = ax_table.table(cellText=cell_text,
colLabels=columns,
loc='center',
fontsize=20,
rowColours=table_colors)