| 5759 | @image_comparison(['vlines_basic.png', 'vlines_with_nan.png', 'vlines_masked.png'], |
| 5760 | style='mpl20') |
| 5761 | def test_vlines(): |
| 5762 | # normal |
| 5763 | x1 = [2, 3, 4, 5, 7] |
| 5764 | y1 = [2, -6, 3, 8, 2] |
| 5765 | fig1, ax1 = plt.subplots() |
| 5766 | ax1.vlines(x1, 0, y1, colors='g', linewidth=5) |
| 5767 | |
| 5768 | # GH #7406 |
| 5769 | x2 = [2, 3, 4, 5, 6, 7] |
| 5770 | y2 = [2, -6, 3, 8, np.nan, 2] |
| 5771 | fig2, (ax2, ax3, ax4) = plt.subplots(nrows=3, figsize=(4, 8)) |
| 5772 | ax2.vlines(x2, 0, y2, colors='g', linewidth=5) |
| 5773 | |
| 5774 | x3 = [2, 3, 4, 5, 6, 7] |
| 5775 | y3 = [np.nan, 2, -6, 3, 8, 2] |
| 5776 | ax3.vlines(x3, 0, y3, colors='r', linewidth=3, linestyle='--') |
| 5777 | |
| 5778 | x4 = [2, 3, 4, 5, 6, 7] |
| 5779 | y4 = [np.nan, 2, -6, 3, 8, np.nan] |
| 5780 | ax4.vlines(x4, 0, y4, colors='k', linewidth=2) |
| 5781 | |
| 5782 | # tweak the x-axis so we can see the lines better |
| 5783 | for ax in [ax1, ax2, ax3, ax4]: |
| 5784 | ax.set_xlim(0, 10) |
| 5785 | |
| 5786 | # check that the y-lims are all automatically the same |
| 5787 | assert ax1.get_ylim() == ax2.get_ylim() |
| 5788 | assert ax1.get_ylim() == ax3.get_ylim() |
| 5789 | assert ax1.get_ylim() == ax4.get_ylim() |
| 5790 | |
| 5791 | fig3, ax5 = plt.subplots() |
| 5792 | x5 = np.ma.masked_equal([2, 4, 6, 8, 10, 12], 8) |
| 5793 | ymin5 = np.ma.masked_equal([0, 1, -1, 0, 2, 1], 2) |
| 5794 | ymax5 = np.ma.masked_equal([13, 14, 15, 16, 17, 18], 18) |
| 5795 | ax5.vlines(x5, ymin5, ymax5, colors='k', linewidth=2) |
| 5796 | ax5.set_xlim(0, 15) |
| 5797 | |
| 5798 | |
| 5799 | def test_vlines_default(): |