Skip to content

Figure linewidth not documented and not visible when saved #9370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tdpetrou opened this issue Oct 11, 2017 · 8 comments
Closed

Figure linewidth not documented and not visible when saved #9370

tdpetrou opened this issue Oct 11, 2017 · 8 comments
Milestone

Comments

@tdpetrou
Copy link
Contributor

tdpetrou commented Oct 11, 2017

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

@WeatherGod
Copy link
Member

WeatherGod commented Oct 11, 2017 via email

@jklymak
Copy link
Member

jklymak commented Oct 11, 2017

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...

@tdpetrou
Copy link
Contributor Author

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

@anntzer
Copy link
Contributor

anntzer commented Oct 11, 2017

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

@WeatherGod
Copy link
Member

WeatherGod commented Oct 11, 2017 via email

@anntzer
Copy link
Contributor

anntzer commented Oct 11, 2017

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).

@jklymak
Copy link
Member

jklymak commented Oct 11, 2017

I reproduced in MacOSX backend.

@QuLogic
Copy link
Member

QuLogic commented Jun 3, 2021

I believe this is fixed by #15111.

@QuLogic QuLogic closed this as completed Jun 3, 2021
@QuLogic QuLogic added this to the v3.3.0 milestone Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants