Home > Blockchain >  How to move or remove the legend from a seaborn JointGrid or jointplot
How to move or remove the legend from a seaborn JointGrid or jointplot

Time:08-04

How to remove the legend in the enter image description here

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()

CodePudding user response:

  • To remove the legend, the correct part of the enter image description here

    • Moving the JointGrid legend can be done with sns.move_legend, as shown in this enter image description here


      With sns.jointplot

      • g.ax_joint.legend_.remove() can be used, but removing the legend is more easily accomplished by passing legend=False to the plot: sns.jointplot(..., legend=False).
      • g.ax_joint. is still required to move the legend.
      penguins = sns.load_dataset("penguins")
      g = sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")
      
      # remove the legend
      g.ax_joint.legend_.remove()
      
      # or 
      
      # move the legend
      # sns.move_legend(g.ax_joint, "lower right", title='Species', frameon=False)
      
  • Related