@@ -89,6 +89,81 @@ def test_multiple_traces_native_legend():
8989 assert plotly_fig .data [2 ].mode == "lines+markers"
9090
9191
92+
93+ def test_axis_mirror_with_spines_and_ticks ():
94+ """Test that mirror=True when both spines and ticks are visible on both sides."""
95+ fig , ax = plt .subplots ()
96+ ax .plot ([0 , 1 ], [0 , 1 ])
97+
98+ # Show all spines
99+ ax .spines ["top" ].set_visible (True )
100+ ax .spines ["bottom" ].set_visible (True )
101+ ax .spines ["left" ].set_visible (True )
102+ ax .spines ["right" ].set_visible (True )
103+
104+ # Show ticks on all sides
105+ ax .tick_params (top = True , bottom = True , left = True , right = True )
106+
107+ plotly_fig = tls .mpl_to_plotly (fig )
108+
109+ assert plotly_fig .layout .xaxis .mirror == "ticks"
110+ assert plotly_fig .layout .yaxis .mirror == "ticks"
111+
112+
113+ def test_axis_mirror_with_ticks_only ():
114+ """Test that mirror=False when spines are not visible on both sides."""
115+ fig , ax = plt .subplots ()
116+ ax .plot ([0 , 1 ], [0 , 1 ])
117+
118+ # Hide opposite spines
119+ ax .spines ["top" ].set_visible (False )
120+ ax .spines ["right" ].set_visible (False )
121+
122+ # Show ticks on all sides
123+ ax .tick_params (top = True , bottom = True , left = True , right = True )
124+
125+ plotly_fig = tls .mpl_to_plotly (fig )
126+
127+ assert plotly_fig .layout .xaxis .mirror == False
128+ assert plotly_fig .layout .yaxis .mirror == False
129+
130+
131+ def test_axis_mirror_false_with_one_sided_ticks ():
132+ """Test that mirror=True when ticks are only on one side but spines are
133+ visible on both sides."""
134+ fig , ax = plt .subplots ()
135+ ax .plot ([0 , 1 ], [0 , 1 ])
136+
137+ # Default matplotlib behavior - ticks only on bottom and left
138+ ax .tick_params (top = False , bottom = True , left = True , right = False )
139+
140+ plotly_fig = tls .mpl_to_plotly (fig )
141+
142+ assert plotly_fig .layout .xaxis .mirror == True
143+ assert plotly_fig .layout .yaxis .mirror == True
144+
145+
146+ def test_axis_mirror_mixed_configurations ():
147+ """Test different configurations for x and y axes."""
148+ fig , ax = plt .subplots ()
149+ ax .plot ([0 , 1 ], [0 , 1 ])
150+
151+ # X-axis: spines and ticks on both sides (mirror="ticks")
152+ ax .spines ["top" ].set_visible (True )
153+ ax .spines ["bottom" ].set_visible (True )
154+ ax .tick_params (top = True , bottom = True )
155+
156+ # Y-axis: spine only on one side (mirror=False)
157+ ax .spines ["right" ].set_visible (False )
158+ ax .spines ["left" ].set_visible (True )
159+ ax .tick_params (left = True , right = True )
160+
161+ plotly_fig = tls .mpl_to_plotly (fig )
162+
163+ assert plotly_fig .layout .xaxis .mirror == "ticks"
164+ assert plotly_fig .layout .yaxis .mirror == False
165+
166+
92167def test_violinplot_bodies_are_filled_polygons ():
93168 fig , ax = plt .subplots ()
94169 ax .violinplot (np .random .randn (100 , 3 ))
0 commit comments