test_axis.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.axis import XTick
  4. def test_tick_labelcolor_array():
  5. # Smoke test that we can instantiate a Tick with labelcolor as array.
  6. ax = plt.axes()
  7. XTick(ax, 0, labelcolor=np.array([1, 0, 0, 1]))
  8. def test_axis_not_in_layout():
  9. fig1, (ax1_left, ax1_right) = plt.subplots(ncols=2, layout='constrained')
  10. fig2, (ax2_left, ax2_right) = plt.subplots(ncols=2, layout='constrained')
  11. # 100 label overlapping the end of the axis
  12. ax1_left.set_xlim([0, 100])
  13. # 100 label not overlapping the end of the axis
  14. ax2_left.set_xlim([0, 120])
  15. for ax in ax1_left, ax2_left:
  16. ax.set_xticks([0, 100])
  17. ax.xaxis.set_in_layout(False)
  18. for fig in fig1, fig2:
  19. fig.draw_without_rendering()
  20. # Positions should not be affected by overlapping 100 label
  21. assert ax1_left.get_position().bounds == ax2_left.get_position().bounds
  22. assert ax1_right.get_position().bounds == ax2_right.get_position().bounds
  23. def test_translate_tick_params_reverse():
  24. fig, ax = plt.subplots()
  25. kw = {'label1On': 'a', 'label2On': 'b', 'tick1On': 'c', 'tick2On': 'd'}
  26. assert (ax.xaxis._translate_tick_params(kw, reverse=True) ==
  27. {'labelbottom': 'a', 'labeltop': 'b', 'bottom': 'c', 'top': 'd'})
  28. assert (ax.yaxis._translate_tick_params(kw, reverse=True) ==
  29. {'labelleft': 'a', 'labelright': 'b', 'left': 'c', 'right': 'd'})