From 08b9e443ad29cd67fcf0c9b066400087158e4e8e Mon Sep 17 00:00:00 2001 From: robertoffmoura Date: Fri, 8 Aug 2025 12:32:00 +0100 Subject: [PATCH 1/2] Set axis linecolor to black by default when converting from matplotlib figure --- plotly/matplotlylib/renderer.py | 4 ++-- plotly/matplotlylib/tests/test_renderer.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plotly/matplotlylib/renderer.py b/plotly/matplotlylib/renderer.py index d55f86ef3c..7bd5448bc0 100644 --- a/plotly/matplotlylib/renderer.py +++ b/plotly/matplotlylib/renderer.py @@ -154,10 +154,10 @@ def open_axes(self, ax, props): self.axis_ct += 1 # set defaults in axes xaxis = go.layout.XAxis( - anchor="y{0}".format(self.axis_ct), zeroline=False, ticks="inside" + anchor="y{0}".format(self.axis_ct), zeroline=False, ticks="inside", linecolor="black" ) yaxis = go.layout.YAxis( - anchor="x{0}".format(self.axis_ct), zeroline=False, ticks="inside" + anchor="x{0}".format(self.axis_ct), zeroline=False, ticks="inside", linecolor="black" ) # update defaults with things set in mpl mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis( diff --git a/plotly/matplotlylib/tests/test_renderer.py b/plotly/matplotlylib/tests/test_renderer.py index 0d63e4815b..fb2407ab09 100644 --- a/plotly/matplotlylib/tests/test_renderer.py +++ b/plotly/matplotlylib/tests/test_renderer.py @@ -84,3 +84,13 @@ 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_axis_linecolor_defaults_to_black(): + fig, ax = plt.subplots() + ax.plot([0, 1], [0, 1]) + + plotly_fig = tls.mpl_to_plotly(fig) + + assert plotly_fig.layout.xaxis.linecolor == "black" + assert plotly_fig.layout.yaxis.linecolor == "black" From 9e6fea89019e453e81a147386a44f5243ae149b2 Mon Sep 17 00:00:00 2001 From: robertoffmoura Date: Tue, 12 Aug 2025 09:57:42 +0100 Subject: [PATCH 2/2] Run ruff format --- plotly/matplotlylib/renderer.py | 10 ++++++++-- plotly/matplotlylib/tests/test_renderer.py | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plotly/matplotlylib/renderer.py b/plotly/matplotlylib/renderer.py index 7bd5448bc0..275ac889b7 100644 --- a/plotly/matplotlylib/renderer.py +++ b/plotly/matplotlylib/renderer.py @@ -154,10 +154,16 @@ def open_axes(self, ax, props): self.axis_ct += 1 # set defaults in axes xaxis = go.layout.XAxis( - anchor="y{0}".format(self.axis_ct), zeroline=False, ticks="inside", linecolor="black" + anchor="y{0}".format(self.axis_ct), + zeroline=False, + ticks="inside", + linecolor="black", ) yaxis = go.layout.YAxis( - anchor="x{0}".format(self.axis_ct), zeroline=False, ticks="inside", linecolor="black" + anchor="x{0}".format(self.axis_ct), + zeroline=False, + ticks="inside", + linecolor="black", ) # update defaults with things set in mpl mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis( diff --git a/plotly/matplotlylib/tests/test_renderer.py b/plotly/matplotlylib/tests/test_renderer.py index fb2407ab09..6ba385d8c4 100644 --- a/plotly/matplotlylib/tests/test_renderer.py +++ b/plotly/matplotlylib/tests/test_renderer.py @@ -86,6 +86,7 @@ def test_multiple_traces_native_legend(): assert plotly_fig.data[2].mode == "lines+markers" + def test_axis_linecolor_defaults_to_black(): fig, ax = plt.subplots() ax.plot([0, 1], [0, 1])