| 5806 | @image_comparison(['hlines_basic.png', 'hlines_with_nan.png', 'hlines_masked.png'], |
| 5807 | style='mpl20') |
| 5808 | def test_hlines(): |
| 5809 | # normal |
| 5810 | y1 = [2, 3, 4, 5, 7] |
| 5811 | x1 = [2, -6, 3, 8, 2] |
| 5812 | fig1, ax1 = plt.subplots() |
| 5813 | ax1.hlines(y1, 0, x1, colors='g', linewidth=5) |
| 5814 | |
| 5815 | # GH #7406 |
| 5816 | y2 = [2, 3, 4, 5, 6, 7] |
| 5817 | x2 = [2, -6, 3, 8, np.nan, 2] |
| 5818 | fig2, (ax2, ax3, ax4) = plt.subplots(nrows=3, figsize=(4, 8)) |
| 5819 | ax2.hlines(y2, 0, x2, colors='g', linewidth=5) |
| 5820 | |
| 5821 | y3 = [2, 3, 4, 5, 6, 7] |
| 5822 | x3 = [np.nan, 2, -6, 3, 8, 2] |
| 5823 | ax3.hlines(y3, 0, x3, colors='r', linewidth=3, linestyle='--') |
| 5824 | |
| 5825 | y4 = [2, 3, 4, 5, 6, 7] |
| 5826 | x4 = [np.nan, 2, -6, 3, 8, np.nan] |
| 5827 | ax4.hlines(y4, 0, x4, colors='k', linewidth=2) |
| 5828 | |
| 5829 | # tweak the y-axis so we can see the lines better |
| 5830 | for ax in [ax1, ax2, ax3, ax4]: |
| 5831 | ax.set_ylim(0, 10) |
| 5832 | |
| 5833 | # check that the x-lims are all automatically the same |
| 5834 | assert ax1.get_xlim() == ax2.get_xlim() |
| 5835 | assert ax1.get_xlim() == ax3.get_xlim() |
| 5836 | assert ax1.get_xlim() == ax4.get_xlim() |
| 5837 | |
| 5838 | fig3, ax5 = plt.subplots() |
| 5839 | y5 = np.ma.masked_equal([2, 4, 6, 8, 10, 12], 8) |
| 5840 | xmin5 = np.ma.masked_equal([0, 1, -1, 0, 2, 1], 2) |
| 5841 | xmax5 = np.ma.masked_equal([13, 14, 15, 16, 17, 18], 18) |
| 5842 | ax5.hlines(y5, xmin5, xmax5, colors='k', linewidth=2) |
| 5843 | ax5.set_ylim(0, 15) |
| 5844 | |
| 5845 | |
| 5846 | def test_hlines_default(): |