Use plot() function to generate a geometry plot on GeoDataFrame.
Geometry plot is a plot generated on GeoSpatial data or Geometry data, which is the geometry column in teradataml GeoDataFrame. Only the columns with ST_GEOMETRY type are allowed for generating geometry plot.
- The maximum size for ST_GEOMETRY must be less than or equal to 64000.
- The ST_GEOMETRY shape can be POINT, LINESTRING, and so on. POLYGON allows filling of different colors.
- X-Axis is not significant geometry plot.
- Y-Axis can be a tuple or DataFrame Column.
- Geometry plot always requires geometry column and corresponding 'weight' column in a tuple format. 'weight' column represents the weight of a shape mentioned in geometry column.
- If you do not specify geometry column and specifies Y-Axis as DataFrame Column, then the default geometry column is considered for plotting.
Example
The following example describes the density of population for all the states across US in year 1990 by generating the geometry plot on a non default Figure.
- Shapes of US states are generated from Free Blank United States Map in SVG - Resources simplemaps.
- Population data is accessed from Historical Population Change Data (1910-2020) (census.gov) Historical Population Changes.
>>> load_example_data("geodataframe", ["us_population", "us_states_shapes"])
>>> us_population = DataFrame("us_population")
>>> us_population
location_type population_year population state_name Georgia State 1930 2908506.0 Georgia State 1950 3444578.0 Georgia State 1960 3943116.0 Georgia State 1970 4589575.0 Georgia State 1990 6478216.0 Georgia State 2000 8186453.0 Georgia State 1980 5463105.0 Georgia State 1940 3123723.0 Georgia State 1920 2895832.0 Georgia State 1910 2609121.0
>>> us_states_shapes = GeoDataFrame("us_states_shapes")
>>> us_states_shapes
state_name state_shape id NM New Mexico POLYGON ((472.45213 324.75551, VA Virginia POLYGON ((908.75086 270.98255, ND North Dakota POLYGON ((556.50879 73.847349, OK Oklahoma POLYGON ((609.50526 322.91131, WI Wisconsin POLYGON ((705.79187 134.80299, RI Rhode Island POLYGON ((946.50841 152.08022, HI Hawaii POLYGON ((416.34965 514.99923, KY Kentucky POLYGON ((693.17367 317.18459, WV West Virginia POLYGON ((836.73002 223.71281, NJ New Jersey POLYGON ((916.80709 207.30914,
- Join shapes with population and filter only 1990 data.
>>> population_data = us_states_shapes.join(us_population, on=us_population.state_name == us_states_shapes.state_name, lsuffix="us", rsuffix="t2")
>>> population_data = population_data.select(["us_state_name", "state_shape", "population_year", "population"])
>>> population_data_1990 = population_data[population_data.population_year == 1990]
>>> population_data_1990
us_state_name state_shape population_year population 0 New Mexico POLYGON ((472.45213 324.75551, 1990 1515069.0 1 Hawaii POLYGON ((416.34965 514.99923, 1990 1108229.0 2 Kentucky POLYGON ((693.17367 317.18459, 1990 3685296.0 3 New Jersey POLYGON ((916.80709 207.30914, 1990 7730188.0 4 North Dakota POLYGON ((556.50879 73.847349, 1990 638800.0 5 Oklahoma POLYGON ((609.50526 322.91131, 1990 3145585.0 6 West Virginia POLYGON ((836.73002 223.71281, 1990 1793477.0 7 Wisconsin POLYGON ((705.79187 134.80299, 1990 4891769.0 8 Virginia POLYGON ((908.75086 270.98255, 1990 6187358.0 9 Rhode Island POLYGON ((946.50841 152.08022, 1990 1003464.0
>>> from teradataml import Figure
>>> figure = Figure(width=1550, height=860)
>>> figure.heading = "Geometry Plot"
>>> plot_1990 = population_data_1990.plot(y=(population_data_1990.population, population_data_1990.state_shape), cmap='rainbow', figure=figure, reverse_yaxis=True, title="US 1990 Population", xlabel="", ylabel="")
>>> plot_1990.show()