How to remove the legend in the seaborn.JoingGrid plot?
The reference code is like below:
import matplotlib.pyplot as plt
import seaborn as sns
penguins = sns.load_dataset("penguins")
g = sns.JointGrid(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")
g.plot_joint(sns.scatterplot)
sns.boxplot(data=penguins, x=g.hue, y=g.y, ax=g.ax_marg_y)
sns.boxplot(data=penguins, y=g.hue, x=g.x, ax=g.ax_marg_x)
plt.show()
I have tried to use the following methods that are known to work on the other seaborn plots, but failed on the jointplot:
plt.legend([],[], frameon=False)
g._legend.remove()

sns.JointGridmust be accessed.g.ax_jointis where the legend is located..legend(a method that creates a legend) and.legend_(the resulting object). Don't access variables that start with an underscore (_legend), because it indicates they are private.python 3.10,matplotlib 3.5.1,seaborn 0.11.2g.plot_joint(sns.scatterplot, legend=False)may be used instead.sns.JointGridJointGridlegend can be done withsns.move_legend, as shown in this answer.g.ax_joint.With
sns.jointplotg.ax_joint.legend_.remove()can be used, but removing the legend is more easily accomplished by passinglegend=Falseto the plot:sns.jointplot(..., legend=False).g.ax_joint.is still required to move the legend.