Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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

Open
robertoffmoura wants to merge 2 commits into plotly:main
base: main
Choose a base branch
Loading
from robertoffmoura:rm/support-non-ap-xticks
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions plotly/matplotlylib/mpltools.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ def prep_ticks(ax, index, ax_type, props):
tick0 = tickvalues[0]
dticks = [
round(tickvalues[i] - tickvalues[i - 1], 12)
for i in range(1, len(tickvalues) - 1)
for i in range(1, len(tickvalues))
]
if all([dticks[i] == dticks[i - 1] for i in range(1, len(dticks) - 1)]):
if all([dticks[i] == dticks[i - 1] for i in range(1, len(dticks))]):
dtick = tickvalues[1] - tickvalues[0]
else:
warnings.warn(
Expand All @@ -463,6 +463,8 @@ def prep_ticks(ax, index, ax_type, props):
raise TypeError
except (IndexError, TypeError):
axis_dict["nticks"] = props["axes"][index]["nticks"]
if props["axes"][index]["tickvalues"] is not None:
axis_dict["tickvals"] = props["axes"][index]["tickvalues"]
else:
axis_dict["tick0"] = tick0
axis_dict["dtick"] = dtick
Expand Down Expand Up @@ -511,6 +513,15 @@ def prep_ticks(ax, index, ax_type, props):

if formatter == "LogFormatterMathtext":
axis_dict["exponentformat"] = "e"
elif (
formatter == "FuncFormatter" and props["axes"][index]["tickformat"] is not None
):
to_remove = ["dticktickmode"]
for key in to_remove:
if key in axis_dict:
axis_dict.pop(key)
axis_dict["ticktext"] = props["axes"][index]["tickformat"]
axis_dict["tickvals"] = props["axes"][index]["tickvalues"]
return axis_dict


Expand Down
25 changes: 25 additions & 0 deletions plotly/matplotlylib/tests/test_renderer.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,28 @@ def test_multiple_traces_native_legend():
assert plotly_fig.data[0].mode == "lines"
assert plotly_fig.data[1].mode == "markers"
assert plotly_fig.data[2].mode == "lines+markers"



def test_non_arithmetic_progression_xtickvals():
xticks = [0.01, 0.53, 0.75]
plt.figure()
plt.plot([0, 1], [0, 1])
plt.xticks(xticks)

plotly_fig = tls.mpl_to_plotly(plt.gcf())

assert plotly_fig.layout.xaxis.tickvals == tuple(xticks)


def test_non_arithmetic_progression_xticktext():
xtickvals = [0.01, 0.53, 0.75]
xticktext = ["Baseline", "param = 1", "param = 2"]
plt.figure()
plt.plot([0, 1], [0, 1])
plt.xticks(xtickvals, xticktext)

plotly_fig = tls.mpl_to_plotly(plt.gcf())

assert plotly_fig.layout.xaxis.tickvals == tuple(xtickvals)
assert plotly_fig.layout.xaxis.ticktext == tuple(xticktext)

AltStyle によって変換されたページ (->オリジナル) /