Skip to content

Legends cut off in Jupyter Notebooks when plotting with %matplotlib notebook command #9163

Closed
@mtd91429

Description

@mtd91429

Bug report

When using matplotlib in a Jupyter Notebook with the magic %matplotlib notebook, legends placed outside of the axis are cut off.

Code for reproduction

import matplotlib.pyplot as plt
# probably unnecessary/overkill, but reset all parameters to default
plt.rcParams.update(plt.rcParamsDefault)
%matplotlib notebook

fig, ax = plt.subplots(ncols=1, nrows=1)
ax.plot(range(10), label="Plot 1")
ax.plot(range(10, 0, -1), label="Plot 2")
ax.legend(loc='center right', bbox_to_anchor=(1.20, 0.5))

Actual outcome

image

Expected outcome

The legend would be fully displayed as in the following example. This plot obtained by switching to %matplotlib inline
image

Matplotlib version

  • Operating System: Windows 7, x64
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.2
  • Jupyter Server: 5.0.0
  • Other Libraries:

Matplotlib and python were installed using Anaconda

Additional Information
This seems similar to #2530

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions