How to move legend to outside of a seaborn scatterplot?

前端 未结 1 1473
野趣味
野趣味 2021-02-15 01:29
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set(style="darkgrid")

g = sns.scatterplot(x="Area", y="Rent/Sqft&         


        
1条回答
  •  别那么骄傲
    2021-02-15 02:22

    Please try the following:

    g.legend(loc='center left', bbox_to_anchor=(1.25, 0.5), ncol=1)

    You can change the first number to negative to put your legend on the left side if you want.

    If you're using Jupyter IDE, you need to put both lines of your code in the same cell and run them together to get the output. In addition, there is no such thing as sns object. Most of the functions in seaborn return a matplotlib Axes object where you can use all the methods associated with the Axes object, like the one (i.e., .legend()) you are using here.

    0 讨论(0)
提交回复
热议问题