Skip to content

Export tick label colors to the plotly tickfont - #5716

Open
robertoffmoura wants to merge 1 commit into
plotly:mainfrom
robertoffmoura:rm/export-tick-label-color
Open

robertoffmoura wants to merge 1 commit into
plotly:mainfrom
robertoffmoura:rm/export-tick-label-color

Conversation

@robertoffmoura

Copy link
Copy Markdown
Contributor

Tick label colors are dropped by the converter. The mplexporter does not export the tick label color, so the plotly tickfont gets a size with no color and tick labels always render in plotly's default dark grey, which is nearly invisible on dark figures (e.g. plt.style.use("dark_background")).

Fix: the mplexporter axis properties now export the tick label color, and prep_xy_axis passes it through to the plotly tickfont.

Snippet to reproduce:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
import plotly.tools as tls

plt.style.use("dark_background")

fig, ax = plt.subplots()
ax.plot(np.sin(np.linspace(0, 6, 100)))
fig.savefig("ticks_mpl.png")

p = tls.mpl_to_plotly(fig)   # tickfont.color was None before the fix
p.write_image("ticks_plotly.png")
matplotlib plotly before plotly after
ticks_mpl ticks_plotly_before ticks_plotly_after

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Transparent colors strike again! Could you please address the comments and add a changelog entry? Thanks for all of your work in this area.

labels = axis.get_ticklabels()
if labels:
props["fontsize"] = labels[0].get_fontsize()
props["fontcolor"] = export_color(labels[0].get_color())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

export_color can produce "none" for transparent labels. As is, this could crash the conversion.

tickfont=dict(size=props["axes"][0]["fontsize"]),
tickfont=dict(
size=props["axes"][0]["fontsize"],
color=props["axes"][0]["fontcolor"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could wrap this (and below) in _export_color to address the "none" color issue.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants