.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_california_districts.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_california_districts.py: Choropleth of California districts with alternative binning schemes =================================================================== This example demonstrates the continuous and categorical binning schemes available in ``geoplot`` on a sample dataset of California congressional districts. A binning scheme (or classifier) is a methodology for splitting a sequence of observations into some number of bins (classes). It is also possible to have no binning scheme, in which case the data is passed through to ``cmap`` as-is. The options demonstrated are: * scheme=None—A continuous colormap. * scheme="Quantiles"—Bins the data such that the bins contain equal numbers of samples. * scheme="EqualInterval"—Bins the data such that bins are of equal length. * scheme="FisherJenks"—Bins the data using the Fisher natural breaks optimization procedure. To learn more about colormaps in general, refer to the :ref:`/user_guide/Customizing_Plots.ipynb#hue` reference in the documentation. This demo showcases a small subset of the classifiers available in ``mapclassify``, the library that ``geoplot`` relies on for this feature. To learn more about ``mapclassify``, including how you can build your own custom ``UserDefined`` classifier, refer to `the mapclassify docs `_. .. GENERATED FROM PYTHON SOURCE LINES 26-66 .. image:: /gallery/images/sphx_glr_plot_california_districts_001.png :alt: California State Districts by Area, 2010, scheme=None, scheme="Quantiles", scheme="EqualInterval", scheme="FisherJenks" :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/alekseybilogur/Desktop/geoplot/examples/plot_california_districts.py:35: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. cali = cali.assign(area=cali.geometry.area) /Users/alekseybilogur/Desktop/geoplot/examples/plot_california_districts.py:46: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. scheme = mc.Quantiles(cali.area, k=5) /Users/alekseybilogur/Desktop/geoplot/examples/plot_california_districts.py:52: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. scheme = mc.EqualInterval(cali.area, k=5) /Users/alekseybilogur/Desktop/geoplot/examples/plot_california_districts.py:58: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. scheme = mc.FisherJenks(cali.area, k=5) Text(0.5, 0.98, 'California State Districts by Area, 2010') | .. code-block:: default import geopandas as gpd import geoplot as gplt import geoplot.crs as gcrs import mapclassify as mc import matplotlib.pyplot as plt cali = gpd.read_file(gplt.datasets.get_path('california_congressional_districts')) cali = cali.assign(area=cali.geometry.area) proj = gcrs.AlbersEqualArea(central_latitude=37.16611, central_longitude=-119.44944) fig, axarr = plt.subplots(2, 2, figsize=(12, 12), subplot_kw={'projection': proj}) gplt.choropleth( cali, hue='area', linewidth=0, scheme=None, ax=axarr[0][0] ) axarr[0][0].set_title('scheme=None', fontsize=18) scheme = mc.Quantiles(cali.area, k=5) gplt.choropleth( cali, hue='area', linewidth=0, scheme=scheme, ax=axarr[0][1] ) axarr[0][1].set_title('scheme="Quantiles"', fontsize=18) scheme = mc.EqualInterval(cali.area, k=5) gplt.choropleth( cali, hue='area', linewidth=0, scheme=scheme, ax=axarr[1][0] ) axarr[1][0].set_title('scheme="EqualInterval"', fontsize=18) scheme = mc.FisherJenks(cali.area, k=5) gplt.choropleth( cali, hue='area', linewidth=0, scheme=scheme, ax=axarr[1][1] ) axarr[1][1].set_title('scheme="FisherJenks"', fontsize=18) plt.subplots_adjust(top=0.92) plt.suptitle('California State Districts by Area, 2010', fontsize=18) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.023 seconds) .. _sphx_glr_download_gallery_plot_california_districts.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_california_districts.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_california_districts.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_