Skip to content

Add support for overriding x tick with non arithmetic progression values - #5262

Open
robertoffmoura wants to merge 2 commits into
plotly:mainfrom
robertoffmoura:rm/support-non-ap-xticks
Open

Add support for overriding x tick with non arithmetic progression values#5262
robertoffmoura wants to merge 2 commits into
plotly:mainfrom
robertoffmoura:rm/support-non-ap-xticks

Conversation

@robertoffmoura

Copy link
Copy Markdown
Contributor

Hi,
This change adds support for specifying tickvals and ticktext when the values don't follow an arithmetic progression, i.e., they're not evenly spaced.

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.

@gvwilson
gvwilson requested a review from emilykl July 3, 2025 14:54
@gvwilson gvwilson added P1 needed for current cycle community community contribution fix fixes something broken labels Jul 3, 2025
@robertoffmoura
robertoffmoura force-pushed the rm/support-non-ap-xticks branch 2 times, most recently from 00a6f11 to 128dd25 Compare August 12, 2025 09:31
@robertoffmoura
robertoffmoura force-pushed the rm/support-non-ap-xticks branch from 128dd25 to 85745d7 Compare October 9, 2025 15:42
@robertoffmoura
robertoffmoura force-pushed the rm/support-non-ap-xticks branch from 85745d7 to 7701120 Compare July 31, 2026 17:18
@robertoffmoura

Copy link
Copy Markdown
Contributor Author

Hi @emilykl,
This adds support for x ticks that don't follow an arithmetic progression when converting matplotlib figures to plotly.

Currently, the conversion ignores custom x tick values specified in the matplotlib figure.

See the snippet below, which prints None before this change:

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

xticks = [0.01, 0.53, 0.75]  # non-arithmetic progression

fig = plt.figure()
plt.plot([0, 1], [0, 1])
plt.xticks(xticks)
fig.savefig("matplotlib.png")

p = tls.mpl_to_plotly(plt.gcf())
print(p.layout.xaxis.tickvals) # (0.01, 0.53, 0.75)
p.write_image("plotly.png")

Here's a screenshot of the matplotlib figure with custom x tick values:
matplotlib

Before this change, the plotly conversion ignores the 0.75 x tick value.
plotly_before

After this change, the converted plot correctly shows the 0.75 x tick value.
plotly_after

@robertoffmoura
robertoffmoura force-pushed the rm/support-non-ap-xticks branch from b446bfd to 266aae9 Compare August 10, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community community contribution fix fixes something broken P1 needed for current cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants