geopandas.GeoDataFrame.plot

GeoDataFrame.plot()

Plot a GeoDataFrame.

Generate a plot of a GeoDataFrame with matplotlib. If a column is specified, the plot coloring will be based on values in that column.

Parameters
columnstr, np.array, pd.Series (default None)

The name of the dataframe column, np.array, or pd.Series to be plotted. If np.array or pd.Series are used then it must have same length as dataframe. Values are used to color the plot. Ignored if color is also set.

kind: str
The kind of plots to produce:
  • ‘geo’: Map (default)

Pandas Kinds - ‘line’ : line plot - ‘bar’ : vertical bar plot - ‘barh’ : horizontal bar plot - ‘hist’ : histogram - ‘box’ : BoxPlot - ‘kde’ : Kernel Density Estimation plot - ‘density’ : same as ‘kde’ - ‘area’ : area plot - ‘pie’ : pie plot - ‘scatter’ : scatter plot - ‘hexbin’ : hexbin plot.

cmapstr (default None)

The name of a colormap recognized by matplotlib.

colorstr (default None)

If specified, all objects will be colored uniformly.

axmatplotlib.pyplot.Artist (default None)

axes on which to draw the plot

caxmatplotlib.pyplot Artist (default None)

axes on which to draw the legend in case of color map.

categoricalbool (default False)

If False, cmap will reflect numerical values of the column being plotted. For non-numerical columns, this will be set to True.

legendbool (default False)

Plot a legend. Ignored if no column is given, or if color is given.

schemestr (default None)

Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. ‘BoxPlot’, ‘EqualInterval’, ‘FisherJenks’, ‘FisherJenksSampled’, ‘HeadTailBreaks’, ‘JenksCaspall’, ‘JenksCaspallForced’, ‘JenksCaspallSampled’, ‘MaxP’, ‘MaximumBreaks’, ‘NaturalBreaks’, ‘Quantiles’, ‘Percentiles’, ‘StdMean’, ‘UserDefined’). Arguments can be passed in classification_kwds.

kint (default 5)

Number of classes (ignored if scheme is None)

vminNone or float (default None)

Minimum value of cmap. If None, the minimum data value in the column to be plotted is used.

vmaxNone or float (default None)

Maximum value of cmap. If None, the maximum data value in the column to be plotted is used.

markersizestr or float or sequence (default None)

Only applies to point geometries within a frame. If a str, will use the values in the column of the frame specified by markersize to set the size of markers. Otherwise can be a value to apply to all points, or a sequence of the same length as the number of points.

figsizetuple of integers (default None)

Size of the resulting matplotlib.figure.Figure. If the argument axes is given explicitly, figsize is ignored.

legend_kwdsdict (default None)

Keyword arguments to pass to matplotlib.pyplot.legend() or matplotlib.pyplot.colorbar(). Additional accepted keywords when scheme is specified:

fmtstring

A formatting specification for the bin edges of the classes in the legend. For example, to have no decimals: {"fmt": "{:.0f}"}.

labelslist-like

A list of legend labels to override the auto-generated labels. Needs to have the same number of elements as the number of classes (k).

intervalboolean (default False)

An option to control brackets from mapclassify legend. If True, open/closed interval brackets are shown in the legend.

categorieslist-like

Ordered list-like object of categories to be used for categorical plot.

classification_kwdsdict (default None)

Keyword arguments to pass to mapclassify

missing_kwdsdict (default None)

Keyword arguments specifying color options (as style_kwds) to be passed on to geometries with missing values in addition to or overwriting other style kwds. If None, geometries with missing values are not plotted.

aspect‘auto’, ‘equal’, None or float (default ‘auto’)

Set aspect of axis. If ‘auto’, the default aspect for map plots is ‘equal’; if however data are not projected (coordinates are long/lat), the aspect is by default set to 1/cos(df_y * pi/180) with df_y the y coordinate of the middle of the GeoDataFrame (the mean of the y range of bounding box) so that a long/lat square appears square in the middle of the plot. This implies an Equirectangular projection. If None, the aspect of ax won’t be changed. It can also be set manually (float) as the ratio of y-unit to x-unit.

**style_kwdsdict

Style options to be passed on to the actual plot function, such as edgecolor, facecolor, linewidth, markersize, alpha.

Returns
axmatplotlib axes instance

Examples

>>> df = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
>>> df.head()  
    pop_est      continent                      name iso_a3  gdp_md_est                                           geometry
0     920938        Oceania                      Fiji    FJI      8374.0  MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1   53950935         Africa                  Tanzania    TZA    150600.0  POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2     603253         Africa                 W. Sahara    ESH       906.5  POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3   35623680  North America                    Canada    CAN   1674000.0  MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4  326625791  North America  United States of America    USA  18560000.0  MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
>>> df.plot("pop_est", cmap="Blues")  

See the User Guide page Mapping and Plotting Tools for details.