|
| 1 | +import plotly.tools as tls |
| 2 | + |
| 3 | +from . import plt |
| 4 | + |
| 5 | +def test_axis_mirror_with_spines_and_ticks(): |
| 6 | + """Test that mirror=True when both spines and ticks are visible on both sides.""" |
| 7 | + fig, ax = plt.subplots() |
| 8 | + ax.plot([0, 1], [0, 1]) |
| 9 | + |
| 10 | + # Show all spines |
| 11 | + ax.spines['top'].set_visible(True) |
| 12 | + ax.spines['bottom'].set_visible(True) |
| 13 | + ax.spines['left'].set_visible(True) |
| 14 | + ax.spines['right'].set_visible(True) |
| 15 | + |
| 16 | + # Show ticks on all sides |
| 17 | + ax.tick_params(top=True, bottom=True, left=True, right=True) |
| 18 | + |
| 19 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 20 | + |
| 21 | + assert plotly_fig.layout.xaxis.mirror == "ticks" |
| 22 | + assert plotly_fig.layout.yaxis.mirror == "ticks" |
| 23 | + |
| 24 | + |
| 25 | +def test_axis_mirror_with_ticks_only(): |
| 26 | + """Test that mirror=False when spines are not visible on both sides.""" |
| 27 | + fig, ax = plt.subplots() |
| 28 | + ax.plot([0, 1], [0, 1]) |
| 29 | + |
| 30 | + # Hide opposite spines |
| 31 | + ax.spines['top'].set_visible(False) |
| 32 | + ax.spines['right'].set_visible(False) |
| 33 | + |
| 34 | + # Show ticks on all sides |
| 35 | + ax.tick_params(top=True, bottom=True, left=True, right=True) |
| 36 | + |
| 37 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 38 | + |
| 39 | + assert plotly_fig.layout.xaxis.mirror == False |
| 40 | + assert plotly_fig.layout.yaxis.mirror == False |
| 41 | + |
| 42 | + |
| 43 | +def test_axis_mirror_false_with_one_sided_ticks(): |
| 44 | + """Test that mirror=True when ticks are only on one side but spines are |
| 45 | + visible on both sides.""" |
| 46 | + fig, ax = plt.subplots() |
| 47 | + ax.plot([0, 1], [0, 1]) |
| 48 | + |
| 49 | + # Default matplotlib behavior - ticks only on bottom and left |
| 50 | + ax.tick_params(top=False, bottom=True, left=True, right=False) |
| 51 | + |
| 52 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 53 | + |
| 54 | + assert plotly_fig.layout.xaxis.mirror == True |
| 55 | + assert plotly_fig.layout.yaxis.mirror == True |
| 56 | + |
| 57 | + |
| 58 | +def test_axis_mirror_mixed_configurations(): |
| 59 | + """Test different configurations for x and y axes.""" |
| 60 | + fig, ax = plt.subplots() |
| 61 | + ax.plot([0, 1], [0, 1]) |
| 62 | + |
| 63 | + # X-axis: spines and ticks on both sides (mirror="ticks") |
| 64 | + ax.spines['top'].set_visible(True) |
| 65 | + ax.spines['bottom'].set_visible(True) |
| 66 | + ax.tick_params(top=True, bottom=True) |
| 67 | + |
| 68 | + # Y-axis: spine only on one side (mirror=False) |
| 69 | + ax.spines['right'].set_visible(False) |
| 70 | + ax.spines['left'].set_visible(True) |
| 71 | + ax.tick_params(left=True, right=True) |
| 72 | + |
| 73 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 74 | + |
| 75 | + assert plotly_fig.layout.xaxis.mirror == "ticks" |
| 76 | + assert plotly_fig.layout.yaxis.mirror == False |
0 commit comments