def test_plot_matrix(data): "Plot the data passing in a matrix and specifying columns" fig = Figure() fig.plot( data=data, region=[10, 70, -5, 10], projection="M10i", style="cc", color="#aaaaaa", B="a", columns="0,1,2+s0.005", ) return fig
def test_plot_projection(data): "Plot the data in green squares with a projection" fig = Figure() fig.plot( x=data[:, 0], y=data[:, 1], region="g", projection="R270/4i", style="s0.2c", color="green", frame="ag", ) return fig
def test_plot_colors_sizes_proj(data, region): "Plot the data using z as sizes and colors with a projection" fig = Figure() fig.coast(region=region, projection="M10i", frame="af", water="skyblue") fig.plot( x=data[:, 0], y=data[:, 1], color=data[:, 2], sizes=0.5 * data[:, 2], style="cc", cmap="copper", ) return fig
def test_legend_default_position(): """ Test using the default legend position. """ fig = Figure() fig.basemap(region=[-1, 1, -1, 1], frame=True) fig.plot(x=[0], y=[0], style="p10p", label="Default") fig.legend() return fig
def test_plot_matrix_color(data): """ Plot the data passing in a matrix and using a colormap. """ fig = Figure() fig.plot( data=data, region=[10, 70, -5, 10], projection="X10c", style="c0.5c", cmap="rainbow", frame="a", ) return fig
def test_plot_lines_with_arrows(): """Plot lines with arrows. The test is slightly different from test_plot_vectors(). Here the vectors are plotted as lines, with arrows at the end. The test also check if the API crashes. See https://github.com/GenericMappingTools/pygmt/issues/406. """ fig = Figure() fig.basemap(region=[-2, 2, -2, 2], frame=True) fig.plot(x=[-1.0, -1.0], y=[-1.0, 1.0], pen="1p,black+ve0.2c") fig.plot(x=[1.0, 1.0], y=[-1.0, 1.0], pen="1p,black+ve0.2c") return fig
def test_plot_sizes(data, region): "Plot the data using z as sizes" fig = Figure() fig.plot( x=data[:, 0], y=data[:, 1], sizes=0.5 * data[:, 2], region=region, projection="X4i", style="cc", color="blue", frame="af", ) return fig
def test_geopandas_plot_non_default_circle(): """ Check the default behavior of plotting geopandas DataFrame with Point geometry in 2d. """ point = shapely.geometry.Point(1, 2) gdf = gpd.GeoDataFrame(geometry=[point]) fig = Figure() fig.plot(data=gdf, region=[0, 2, 1, 3], projection="X2c", frame=True, style="c0.2c") return fig
def test_plot_matrix(data, color): """ Plot the data passing in a matrix and specifying columns. """ fig = Figure() fig.plot( data=data, region=[10, 70, -5, 10], projection="M15c", style="cc", color=color, frame="a", incols="0,1,2+s0.5", ) return fig
def test_plot_from_file(region): """ Plot using the data file name instead of loaded data. """ fig = Figure() fig.plot( data=POINTS_DATA, region=region, projection="X10c", style="d1c", color="yellow", frame=True, incols=[0, 1], ) return fig
def test_plot_red_circles(data, region): """ Plot the data in red circles passing in vectors. """ fig = Figure() fig.plot( x=data[:, 0], y=data[:, 1], region=region, projection="X10c", style="c0.2c", color="red", frame="afg", ) return fig
def test_plot_colors_sizes(data, region): "Plot the data using z as sizes and colors" fig = Figure() fig.plot( x=data[:, 0], y=data[:, 1], color=data[:, 2], sizes=0.5 * data[:, 2], region=region, projection="X3i", style="cc", cmap="copper", frame="af", ) return fig
def test_makecpt_plot_points(points, region): """ Use static color palette table to change color of points. """ fig = Figure() makecpt(cmap="rainbow") fig.plot( x=points[:, 0], y=points[:, 1], color=points[:, 2], region=region, style="c1c", cmap=True, ) return fig
def test_plot_colors(data, region): """ Plot the data using z as colors. """ fig = Figure() fig.plot( x=data[:, 0], y=data[:, 1], color=data[:, 2], region=region, projection="X10c", style="c0.5c", cmap="cubhelix", frame="af", ) return fig
def test_plot_dataframe_incols(): """ Make sure that the incols parameter works for pandas.DataFrame. See https://github.com/GenericMappingTools/pygmt/issues/1440. """ data = pd.DataFrame(data={ "col1": [-0.5, 0, 0.5], "col2": [-0.75, 0, 0.75] }) fig = Figure() fig.plot(data=data, frame=True, region=[-1, 1, -1, 1], projection="X5c", incols=[1, 0]) return fig
def test_legend_position(): """ Try positioning with each of the four legend coordinate systems. """ fig = Figure() fig.basemap(region=[-2, 2, -2, 2], frame=True) positions = ["jTR+jTR", "g0/1", "n0.2/0.2", "x4i/2i/2i"] for i, position in enumerate(positions): fig.plot(x=[0], y=[0], style="p10p", label=i) fig.legend(position=position, box=True) return fig
def test_plot_vectors(): "Plot vectors" azimuth = np.array([0, 45, 90, 135, 180, 225, 270, 310]) lengths = np.linspace(0.1, 1, len(azimuth)) lon = np.sin(np.deg2rad(azimuth)) lat = np.cos(np.deg2rad(azimuth)) fig = Figure() fig.plot( x=lon, y=lat, direction=(azimuth, lengths), region="-2/2/-2/2", projection="X4i", style="V0.2c+e", color="black", frame="af", ) return fig
def test_plot_ogrgmt_file_multipoint_default_style(func): """ Make sure that OGR/GMT files with MultiPoint geometry are plotted as squares and not as line (default GMT style). """ with GMTTempFile(suffix=".gmt") as tmpfile: gmt_file = """# @VGMT1.0 @GMULTIPOINT # @R1/1/1/1UB # FEATURE_DATA 1 2 """ with open(tmpfile.name, "w", encoding="utf8") as file: file.write(gmt_file) fig = Figure() fig.plot(data=func(tmpfile.name), region=[0, 2, 1, 3], projection="X2c", frame=True) return fig
def test_plot_datetime(): """ Test various datetime input data. """ fig = Figure() fig.basemap( projection="X15c/5c", region=[ np.array("2010-01-01T00:00:00", dtype=np.datetime64), pd.Timestamp("2020-01-01"), 0, 10, ], frame=True, ) # numpy.datetime64 types x = np.array( ["2010-06-01", "2011-06-01T12", "2012-01-01T12:34:56"], dtype="datetime64" ) y = [1.0, 2.0, 3.0] fig.plot(x, y, style="c0.2c", pen="1p") # pandas.DatetimeIndex x = pd.date_range("2013", freq="YS", periods=3) y = [4, 5, 6] fig.plot(x, y, style="t0.2c", pen="1p") # xarray.DataArray x = xr.DataArray(data=pd.date_range(start="2015-03", freq="QS", periods=3)) y = [7.5, 6, 4.5] fig.plot(x, y, style="s0.2c", pen="1p") # raw datetime strings x = ["2016-02-01", "2017-03-04T00:00"] y = [7, 8] fig.plot(x, y, style="a0.2c", pen="1p") # the Python built-in datetime and date x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 1, 1)] y = [8.5, 9.5] fig.plot(x, y, style="i0.2c", pen="1p") return fig
def test_plot_transparency(): """ Plot the data with a constant transparency. """ x = np.arange(1, 10) y = np.arange(1, 10) fig = Figure() fig.plot( x=x, y=y, region=[0, 10, 0, 10], projection="X10c", frame=True, style="c0.2c", color="blue", transparency=80.0, ) return fig
def test_plot_varying_transparency(): """ Plot the data using z as transparency. """ x = np.arange(1, 10) y = np.arange(1, 10) z = np.arange(1, 10) * 10 fig = Figure() fig.plot( x=x, y=y, region=[0, 10, 0, 10], projection="X10c", frame=True, style="c0.2c", color="blue", transparency=z, ) return fig
def test_plot_varying_intensity(): """ Plot the data with array-like intensity. """ x = np.arange(-1, 1.1, 0.1) y = np.zeros(x.size) intensity = x fig = Figure() fig.plot( x=x, y=y, region=[-1.1, 1.1, -0.5, 0.5], projection="X10c/2c", frame=["S", "xaf+lIntensity"], style="c0.25c", color="blue", intensity=intensity, ) return fig
def test_plot_deprecate_columns_to_incols(region): """ Make sure that the old parameter "columns" is supported and it reports a warning. Modified from the test_plot_from_file() test. """ fig = Figure() with pytest.warns(expected_warning=FutureWarning) as record: fig.plot( data=POINTS_DATA, region=region, projection="X10c", style="d1c", color="yellow", frame=True, columns=[0, 1], ) assert len(record) == 1 # check that only one warning was raised return fig
def test_plot_ogrgmt_file_multipoint_non_default_style(): """ Make sure that non-default style can be set for plotting OGR/GMT file. """ with GMTTempFile(suffix=".gmt") as tmpfile: gmt_file = """# @VGMT1.0 @GPOINT # @R1/1/1/1UB # FEATURE_DATA 1 2 """ with open(tmpfile.name, "w", encoding="utf8") as file: file.write(gmt_file) fig = Figure() fig.plot( data=tmpfile.name, region=[0, 2, 1, 3], projection="X2c", frame=True, style="c0.2c", ) return fig
def test_plot_deprecate_sizes_to_size(data, region): """ Make sure that the old parameter "sizes" is supported and it reports a warning. Modified from the test_plot_sizes() test. """ fig = Figure() with pytest.warns(expected_warning=FutureWarning) as record: fig.plot( x=data[:, 0], y=data[:, 1], sizes=0.5 * data[:, 2], region=region, projection="X10c", style="cc", color="blue", frame="af", ) assert len(record) == 1 # check that only one warning was raised return fig
def test_legend_entries(): """ Test different marker types/shapes. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image fig_ref = Figure() fig_ref.basemap(J="x1i", R="0/7/3/7", B="") fig_ref.plot( data="@Table_5_11.txt", S="c0.15i", G="lightgreen", W="faint", l="Apples", ) fig_ref.plot(data="@Table_5_11.txt", W="1.5p,gray", l='"My lines"') fig_ref.plot(data="@Table_5_11.txt", S="t0.15i", G="orange", l="Oranges") fig_ref.legend(D="JTR+jTR") fig_test.basemap(projection="x1i", region=[0, 7, 3, 7], frame=True) fig_test.plot( data="@Table_5_11.txt", style="c0.15i", color="lightgreen", pen="faint", label="Apples", ) fig_test.plot(data="@Table_5_11.txt", pen="1.5p,gray", label='"My lines"') fig_test.plot( data="@Table_5_11.txt", style="t0.15i", color="orange", label="Oranges" ) fig_test.legend(position="JTR+jTR") return fig_ref, fig_test
def test_plot_fail_size_color(data): "Should raise an exception if array sizes and color are used with matrix" fig = Figure() with pytest.raises(GMTInvalidInput): fig.plot( data=data, region=region, projection="X4i", style="c0.2c", color=data[:, 2], frame="afg", ) with pytest.raises(GMTInvalidInput): fig.plot( data=data, region=region, projection="X4i", style="cc", sizes=data[:, 2], color="red", frame="afg", )
def test_plot_scalar_xy(): "Plot symbols given scalar x, y coordinates" fig = Figure() fig.basemap(region=[-2, 2, -2, 2], frame=True) fig.plot(x=-1.5, y=1.5, style="c1c") fig.plot(x=0, y=0, style="t1c") fig.plot(x=1.5, y=-1.5, style="s1c") return fig
def test_plot_fail_1d_array_with_data(data): """ Should raise an exception if array color, size, intensity and transparency are used with matrix. """ fig = Figure() kwargs = dict(data=data, region=region, projection="X10c", frame="afg") with pytest.raises(GMTInvalidInput): fig.plot(style="c0.2c", color=data[:, 2], **kwargs) with pytest.raises(GMTInvalidInput): fig.plot(style="cc", size=data[:, 2], color="red", **kwargs) with pytest.raises(GMTInvalidInput): fig.plot(style="c0.2c", color="red", intensity=data[:, 2], **kwargs) with pytest.raises(GMTInvalidInput): fig.plot(style="c0.2c", color="red", transparency=data[:, 2] * 100, **kwargs)
def test_plot_projection(data): """ Plot the data in green squares with a projection. """ fig_ref, fig_test = Figure(), Figure() fig_ref.plot( data=POINTS_DATA, R="g", J="R270/4i", S="s0.2c", G="green", B="ag", ) fig_test.plot( x=data[:, 0], y=data[:, 1], region="g", projection="R270/4i", style="s0.2c", color="green", frame="ag", ) return fig_ref, fig_test