1

How can we add multiple legends in Seaborn jointplot? I`m creating a hexbin jointplot with seaborn, and I want to have two legends, scaling in vertical direction instead of horizontal.

First, how can I have both legends as separate and legend for dates scaling vertically instead of horizontally.

I had a look at these links. Correctly add a legend to a seaborn jointplot and Getting legend in seaborn jointplot

And would it also be possible to have the same background for Hexbins instead of white, which doesn`t match with Seaborn style? And can I also make grid square, instead of rectangular?

sns.set()

g = sns.jointplot(x=x,y=y, kind="hex",color="#4CB391", height=15)
ax = g.ax_joint

sns.regplot(x = new_x,y= new_y, ax=ax, scatter=False)
sns.regplot(x = y_true['fatigue_dem_1'],y= y_true['fatigue_dem_1'], color='red',ax=ax, scatter=False)

g.set_axis_labels('Estimated', 'Predicted', fontsize=20)
g.fig.suptitle("Fatigue Dem 1", fontsize=20)

# adjustment for colorbar
plt.subplots_adjust(left=0.2, right=0.8, top=0.95, bottom=0.2)
# make new ax object for the cbar
cbar_ax = g.fig.add_axes([.85, .2, .05, .6])  # x, y, width, height
plt.colorbar(cax=cbar_ax)


metric_legend, = g.ax_joint.plot([], [], linestyle="", alpha=0.5)
data_legend, = g.ax_joint.plot([], [], linestyle="", alpha=0.5)

g.ax_joint.legend([metric_legend],['rrmse={:f}, r2_score={:f}'.format(rrmse,r2)],  fontsize=14)
g.ax_joint.legend([data_legend],['Start Date: {0}, End Date: {1}, purpose: {2}'.format(start_date, end_date, 'Test')],  fontsize=14)

Legend for Metadata

Legend for Metrics

  • With your variable names, putting both in a list should work_ `g.ax_joint.legend([metric_legend, data_legend], ["text1", "text2"], ...)` – JohanC Jun 28 '21 at 15:03

0 Answers0