GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use matplotlib background colors when converting from matplotlib by robertoffmoura · Pull Request #5285 · plotly/plotly.py

Conversation

@robertoffmoura

@robertoffmoura robertoffmoura commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gvwilson gvwilson self-assigned this Aug 1, 2025
@gvwilson gvwilson added feature something new P1 needed for current cycle community community contribution labels Aug 1, 2025
gvwilson
gvwilson approved these changes Aug 1, 2025
View reviewed changes
@robertoffmoura
robertoffmoura force-pushed the rm/default-plot_bgcolor-white branch 2 times, most recently from 373d9e7 to 18abcb6 Compare August 12, 2025 09:31
@emilykl

emilykl commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

Hi @robertoffmoura , the default for layout.plot_bgcolor is already white, do you have an example of where the current default is not working?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robertoffmoura
robertoffmoura force-pushed the rm/default-plot_bgcolor-white branch from 18abcb6 to 2ac7771 Compare October 9, 2025 15:42
@LiamConnors LiamConnors unassigned gvwilson Jan 29, 2026
@robertclaus

robertclaus commented Aug 6, 2026

Copy link
Copy Markdown

@robertoffmoura given the age and last comment in this PR - should it be closed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robertoffmoura
robertoffmoura force-pushed the rm/default-plot_bgcolor-white branch from 2ac7771 to 644d12c Compare August 10, 2026 11:31
@robertoffmoura robertoffmoura changed the title Set plot_bgcolor to white by default when converting from matplotlib Use matplotlib background colors when converting from matplotlib Aug 10, 2026
@robertoffmoura

robertoffmoura commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Hi @robertclaus,

I updated the PR to set plot_bgcolor and paper_bgcolor based on fig.patch.get_facecolor() and props["axesbg"].

The below snippet prints None None for both figures before the change, and prints the expected color after the change.

Snippet:

import matplotlib.pyplot as plt
import plotly.tools as tls

# default matplotlib backgrounds -> white
fig1, ax1 = plt.subplots()
ax1.plot([0, 1], [0, 1])
p1 = tls.mpl_to_plotly(fig1)
print(p1.layout.plot_bgcolor, p1.layout.paper_bgcolor)  # #FFFFFF #FFFFFF
fig1.savefig("matplotlib.png")
p1.write_image("plotly.png")

# custom backgrounds -> faithfully preserved
fig2, ax2 = plt.subplots()
fig2.patch.set_facecolor("lightyellow")
ax2.set_facecolor("lightgray")
ax2.plot([0, 1], [0, 1])
p2 = tls.mpl_to_plotly(fig2)
print(p2.layout.plot_bgcolor, p2.layout.paper_bgcolor)  # #D3D3D3 #FFFFE0

Here's also a screenshot of the matplotlib figure
matplotlib

And the plotly converted figure before the change (unexpected light blue grey background)
plotly

And after the change (expected white background)
plotly2

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robertoffmoura
robertoffmoura force-pushed the rm/default-plot_bgcolor-white branch from 644d12c to bc1e2a3 Compare August 10, 2026 19:46
@robertclaus
robertclaus requested a review from camdecoster August 13, 2026 19:55
@robertclaus robertclaus assigned camdecoster Aug 13, 2026
@robertoffmoura
robertoffmoura force-pushed the rm/default-plot_bgcolor-white branch from bc1e2a3 to 7c7b0ce Compare August 21, 2026 18:25
camdecoster
camdecoster reviewed Aug 27, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of suggestions, but this looks pretty good overall. Could you please add a CHANGELOG entry and merge origin/main? That should fix the failing test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread plotly/matplotlylib/renderer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@robertoffmoura
Set plot_bgcolor and paper_bgcolor from matplotlib figure backgrounds
b865431
@robertoffmoura
robertoffmoura force-pushed the rm/default-plot_bgcolor-white branch from 7c7b0ce to b865431 Compare August 31, 2026 17:38
robertoffmoura added 2 commits August 31, 2026 18:52
@robertoffmoura
Use mplexporter-exported figbg for paper background color
e5ced3e
@robertoffmoura
Add changelog entry
836c96a
@robertoffmoura
robertoffmoura requested a review from camdecoster August 31, 2026 20:59
camdecoster
camdecoster approved these changes Aug 31, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster
camdecoster merged commit b2cab76 into plotly:main Aug 31, 2026
25 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes
+1 more reviewer
@gvwilson gvwilson gvwilson approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@camdecoster camdecoster

Labels

community community contribution feature something new P1 needed for current cycle

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@robertoffmoura @emilykl @robertclaus @camdecoster @gvwilson
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.