|
| 1 | +""" |
| 2 | +Tests for Figure.vlines. |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +from pygmt import Figure |
| 7 | +from pygmt.exceptions import GMTInvalidInput |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.mpl_image_compare |
| 11 | +def test_vlines_one_line(): |
| 12 | + """ |
| 13 | + Plot one vertical line. |
| 14 | + """ |
| 15 | + fig = Figure() |
| 16 | + fig.basemap(region=[0, 10, 0, 10], projection="X10c/10c", frame=True) |
| 17 | + fig.vlines(1) |
| 18 | + fig.vlines(2, ymin=1) |
| 19 | + fig.vlines(3, ymax=9) |
| 20 | + fig.vlines(4, ymin=3, ymax=8) |
| 21 | + fig.vlines(5, ymin=4, ymax=8, pen="1p,blue", label="Line at y=5") |
| 22 | + fig.vlines(6, ymin=5, ymax=7, pen="1p,red", label="Line at y=6") |
| 23 | + fig.legend() |
| 24 | + return fig |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.mpl_image_compare |
| 28 | +def test_vlines_multiple_lines(): |
| 29 | + """ |
| 30 | + Plot multiple vertical lines. |
| 31 | + """ |
| 32 | + fig = Figure() |
| 33 | + fig.basemap(region=[0, 16, 0, 10], projection="X10c/10c", frame=True) |
| 34 | + fig.vlines([1, 2]) |
| 35 | + fig.vlines([3, 4, 5], ymin=[1, 2, 3]) |
| 36 | + fig.vlines([6, 7, 8], ymax=[7, 8, 9]) |
| 37 | + fig.vlines([9, 10], ymin=[1, 2], ymax=[9, 10]) |
| 38 | + fig.vlines([11, 12], ymin=1, ymax=8, pen="1p,blue", label="Line at y=11,12") |
| 39 | + fig.vlines( |
| 40 | + [13, 14], ymin=[3, 4], ymax=[7, 8], pen="1p,red", label="Line at y=13,14" |
| 41 | + ) |
| 42 | + fig.legend() |
| 43 | + return fig |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.mpl_image_compare |
| 47 | +def test_vlines_clip(): |
| 48 | + """ |
| 49 | + Plot vertical lines with clipping or not. |
| 50 | + """ |
| 51 | + fig = Figure() |
| 52 | + fig.basemap(region=[0, 10, 0, 4], projection="X10c/4c", frame=True) |
| 53 | + fig.vlines(1, ymin=-1, ymax=5) |
| 54 | + fig.vlines(2, ymin=-1, ymax=5, no_clip=True) |
| 55 | + return fig |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.mpl_image_compare |
| 59 | +def test_vlines_geographic_global(): |
| 60 | + """ |
| 61 | + Plot vertical lines in geographic coordinates. |
| 62 | + """ |
| 63 | + fig = Figure() |
| 64 | + fig.basemap(region=[-180, 180, -90, 90], projection="R15c", frame="a30g30") |
| 65 | + fig.vlines(30, pen="1p") |
| 66 | + fig.vlines(90, ymin=-60, pen="1p,blue") |
| 67 | + fig.vlines(-90, ymax=60, pen="1p,blue") |
| 68 | + fig.vlines(120, ymin=-60, ymax=60, pen="1p,blue") |
| 69 | + return fig |
| 70 | + |
| 71 | + |
| 72 | +@pytest.mark.mpl_image_compare |
| 73 | +def test_vlines_polar_projection(): |
| 74 | + """ |
| 75 | + Plot vertical lines in polar projection. |
| 76 | + """ |
| 77 | + fig = Figure() |
| 78 | + fig.basemap(region=[0, 360, 0, 1], projection="P15c", frame=True) |
| 79 | + fig.vlines(0, pen="1p") |
| 80 | + fig.vlines(30, ymin=0, ymax=1, pen="1p") |
| 81 | + fig.vlines(60, ymin=0.5, pen="1p") |
| 82 | + fig.vlines(90, ymax=0.5, pen="1p") |
| 83 | + fig.vlines(120, ymin=0.25, ymax=0.75, pen="1p") |
| 84 | + return fig |
| 85 | + |
| 86 | + |
| 87 | +def test_vlines_invalid_input(): |
| 88 | + """ |
| 89 | + Test invalid input for vlines. |
| 90 | + """ |
| 91 | + fig = Figure() |
| 92 | + fig.basemap(region=[0, 10, 0, 6], projection="X10c/6c", frame=True) |
| 93 | + with pytest.raises(GMTInvalidInput): |
| 94 | + fig.vlines(1, ymin=2, ymax=[3, 4]) |
| 95 | + with pytest.raises(GMTInvalidInput): |
| 96 | + fig.vlines(1, ymin=[2, 3], ymax=4) |
| 97 | + with pytest.raises(GMTInvalidInput): |
| 98 | + fig.vlines(1, xmin=[2, 3], xmax=[4, 5]) |
| 99 | + with pytest.raises(GMTInvalidInput): |
| 100 | + fig.vlines([1, 2], ymin=[2, 3, 4], ymax=3) |
| 101 | + with pytest.raises(GMTInvalidInput): |
| 102 | + fig.vlines([1, 2], ymin=[2, 3], ymax=[4, 5, 6]) |
0 commit comments