FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Legends cut off in Jupyter Notebooks when plotting with %matplotlib notebook command · Issue #9163 · matplotlib/matplotlib · GitHub

Repository navigation

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

Closed

Description

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

Expected outcome

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

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

Activity

  1. jklymak commented on Sep 7, 2017

    Member

    The legend is cut off if you do fig.savefig('Test.pdf') as well.

    %matplotlib inline is just letting you see off the edge of the figure, whereas %matplotlib notebook is giving you a more what-you-see-is-what-you-get view. If you want yout legend over there, you can make the axis smaller (fig.subplots_adjust=0.85).

    An automatic soultion could be offered by fig.tight_layout(), but tight_layout() doesn't take into account legends (yet. see #9130).

  2. jklymak commented on Sep 7, 2017

    Member

    OK, I made a pull request: #9164

  3. timhoffm commented on Jul 16, 2020

    Member

    Closed by #9164.

  4. added this to the v2.2.0 milestone on Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL