Skip to content

Commit c14f3f7

Browse files
Fix y-axis showline and hide tick markers when mpl ticks are hidden
1 parent 3027f17 commit c14f3f7

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

plotly/matplotlylib/renderer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ def open_axes(self, ax, props):
194194
left_spine, right_spine, left_tick_markers, right_tick_markers
195195
)
196196
xaxis["showline"] = bottom_spine
197-
yaxis["showline"] = top_spine
197+
yaxis["showline"] = left_spine
198+
# hide tick markers when the mpl main-side tick markers are hidden
199+
if not bottom_tick_markers:
200+
xaxis["ticks"] = ""
201+
if not left_tick_markers:
202+
yaxis["ticks"] = ""
198203

199204
# put axes in our figure
200205
self.plotly_fig["layout"]["xaxis{0}".format(self.axis_ct)] = xaxis

plotly/matplotlylib/tests/test_renderer.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,46 @@ def test_axis_mirror_mixed_configurations():
273273

274274
assert plotly_fig.layout.xaxis.mirror == "ticks"
275275
assert plotly_fig.layout.yaxis.mirror == False
276+
277+
278+
def test_axis_showline_tied_to_main_spine():
279+
"""Test that showline follows the main-side spine (bottom for x, left for y)."""
280+
fig, ax = plt.subplots()
281+
ax.plot([0, 1], [0, 1])
282+
283+
# Hide the mirror-side spines only
284+
ax.spines["top"].set_visible(False)
285+
ax.spines["right"].set_visible(False)
286+
287+
plotly_fig = tls.mpl_to_plotly(fig)
288+
289+
assert plotly_fig.layout.xaxis.showline == True
290+
assert plotly_fig.layout.yaxis.showline == True
291+
292+
293+
def test_axis_showline_hidden_when_main_spine_hidden():
294+
"""Test that showline is False when the main-side spine is hidden."""
295+
fig, ax = plt.subplots()
296+
ax.plot([0, 1], [0, 1])
297+
298+
# Hide the main-side spines but keep the mirror-side ones
299+
ax.spines["bottom"].set_visible(False)
300+
ax.spines["left"].set_visible(False)
301+
302+
plotly_fig = tls.mpl_to_plotly(fig)
303+
304+
assert plotly_fig.layout.xaxis.showline == False
305+
assert plotly_fig.layout.yaxis.showline == False
306+
307+
308+
def test_ticks_hidden_when_mpl_main_ticks_hidden():
309+
"""Test that tick markers are hidden when the mpl main-side ticks are hidden."""
310+
fig, ax = plt.subplots()
311+
ax.plot([0, 1], [0, 1])
312+
313+
ax.tick_params(top=False, bottom=False, left=False, right=False)
314+
315+
plotly_fig = tls.mpl_to_plotly(fig)
316+
317+
assert plotly_fig.layout.xaxis.ticks == ""
318+
assert plotly_fig.layout.yaxis.ticks == ""

0 commit comments

Comments
 (0)