Skip to content

Figure background colors #7619

Closed
Closed

Description

@darkdragon-001

I find the current handling of background colors very non-intuitive:

  1. figure facecolor is not applied for savefig() by default
  2. figure facecolor is not applied setting frameon=False
  3. axis_bgcolor is not applied when hiding axis lines/ticks via axis('off')

So using a white plain surface to draw objects needs the following code:

fig = figure(..., facecolor='w', edgecolor='None')
ax.axis('equal')        # equal scale
ax.axis('off')          # do not show axis
ax.axis([-1, 1, -1, 1]) # scale to unit lengths
show()
fig.savefig(..., facecolor=fig.get_facecolor(), edgecolor='None', transparent=True)

My suggestion

  • apply same colors to savefig() by default
  • mention in the docs of axis_bgcolor and axis('off') that this setting is ignored
  • mention in the docs of facecolor and frameon that this setting is ignored

Activity

  1. tacaswell commented on Dec 13, 2016

    @tacaswell
    Member

    We are always happy to get PRs to clarify documentation!

    If you do not pass a facecolor it defaults to the value of rcParams['savefig.facecolor'] which should have defaulted to white.

    It is less 'is not applied' than the background patches are simply not drawn if you ask them to not be drawn.

  2. Spenhouet commented on May 25, 2019

    @Spenhouet

    Wow thanks for this thread. I was just about to write a bug report since my figures were always saved with a black facecolor instead of the correct white one (that is also rendered correct in IPython).

    Just adding facecolor=fig.get_facecolor() to the save parameters solved this.
    I agree that this is unintuitive.

  3. added this to the v3.3.0 milestone on May 4, 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