Skip to content

Figure linewidth not documented and not visible when saved #9370

Closed

Description

@tdpetrou

Bug report

Bug summary

When creating a figure it is possible to use linewidth along with edgecolor to create a border around the figure. The linewidth parameter is not shown in the documentation. There is no corresponding set_linewidth figure method.

Also, when saving to a file, this border is missing.

I am using Jupyter notebook.

Code for reproduction

fig = plt.figure(linewidth=20, edgecolor='r')
plt.plot([5,6])
plt.savefig('/Users/Ted/Desktop/figlw.png')

Actual outcome (in notebook)

screen shot 2017-10-11 at 11 32 37 am

Expected outcome

Matplotlib version

  • Operating system: OSX
  • Matplotlib version: 2.1
  • Matplotlib backend (module://ipykernel.pylab.backend_inline):
  • Python version: 3.6
  • Jupyter version (if applicable): 5.0
  • Other libraries:

Updated through conda

Activity

  1. WeatherGod commented on Oct 11, 2017

    @WeatherGod
    Member
  2. jklymak commented on Oct 11, 2017

    @jklymak
    Member

    I can confirm this as the behaviour. plt.show() has the nice red box, printing does not.

    It is documented, at least on master in the Figure class:

    def __init__(self,
                     figsize=None,  # defaults to rc figure.figsize
                     dpi=None,  # defaults to rc figure.dpi
                     facecolor=None,  # defaults to rc figure.facecolor
                     edgecolor=None,  # defaults to rc figure.edgecolor
                     linewidth=0.0,  # the default linewidth of the frame
                     frameon=None,  # whether or not to draw the figure frame
                     subplotpars=None,  # default to rc
                     tight_layout=None,  # default to rc figure.autolayout
                     ):
            """
            *figsize*
                w,h tuple in inches
    
            *dpi*
                Dots per inch
    
            *facecolor*
                The figure patch facecolor; defaults to rc ``figure.facecolor``
    
            *edgecolor*
                The figure patch edge color; defaults to rc ``figure.edgecolor``
    
            *linewidth*
                The figure patch edge linewidth; the default linewidth of the frame

    no idea why its not rendering when a png is saved...

  3. tdpetrou commented on Oct 11, 2017

    @tdpetrou
    ContributorAuthor

    Ok,now I'm confused. I see it documented here at matplotlib.figure.Figure

  4. anntzer commented on Oct 11, 2017

    @anntzer
    Contributor

    fwiw, only occurs in notebook inline backend, not notebook backend

  5. WeatherGod commented on Oct 11, 2017

    @WeatherGod
    Member
  6. anntzer commented on Oct 11, 2017

    @anntzer
    Contributor

    Well. It's still an issue for us because using e.g. qt5agg you get the same discrepancy.

    This is because the figure edgecolor is overridden by the savefig.edgecolor rcParam at save time. Setting rcParams["savefig.edgecolor"] = "r" fixes the issue for qt5agg (I can see why this rcParam (or rather its companion, rcParams["savefig.facecolor"]) used to exist back when the UI interface defaulted to a gray background but you'd want to save figures with a white background, but as usual these days it seems to be more a pain point than anything and I'd suggest either deprecating them or at least switching the default from "w" to something that says "don't touch it").

    But even setting savefig.edgecolor doesn't fix it for jupyter inline mode.

    Also I think the relevant setter method lives on plt.gcf().patch (a Rectangle object).

  7. jklymak commented on Oct 11, 2017

    @jklymak
    Member

    I reproduced in MacOSX backend.

  8. QuLogic commented on Jun 3, 2021

    @QuLogic
    Member

    I believe this is fixed by #15111.

  9. added this to the v3.3.0 milestone on Jun 3, 2021
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