0

For a plot of mine I need to use move_legend with seaborn. Can someone explain, why move_legend does not want to work in Jupyter Notebook? It runs in PyCharm (takes long); but again not in Spyder. I used an example from this link, to test move_legend in JupyterNotebook

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
penguins = sns.load_dataset("penguins")
sns.set_context("talk", font_scale=1)
plt.figure(figsize=(8,6))
ax = sns.scatterplot(data=penguins, 
                     x="bill_length_mm",
                     y="flipper_length_mm",
                     hue="species")
sns.move_legend(
    ax, "lower center",
    bbox_to_anchor=(.5, 1),
    frameon=False,
)
plt.xlabel("Bill Length")
plt.ylabel("Flipper Length")
plt.savefig("Seaborn_move_legend_to_the_top_of_plot.png",
                    format='png',dpi=150)

Out: AttributeError: module 'seaborn' has no attribute 'move_legend'

Thanks

  • 2
    Update seaborn to 0.11.2 as stated in this [answer](https://stackoverflow.com/q/27019079/7758804). [This code works without issue in Jupyter](https://i.stack.imgur.com/sVSPr.png) – Trenton McKinney Oct 05 '22 at 19:46

0 Answers0