.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_usa_city_elevations.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_usa_city_elevations.py: Pointplot of US city elevations with custom scale functions =========================================================== This example plots United States cities by their elevation. Several different possible scaling functions for determining point size are demonstrated. The first plot is a default linear-scale one. We can see from the results that this is clearly the most appropriate one for this specific data. The second plot shows a trivial identity scale. This results in a plot where every city has the same size. A more interesting scale is the logarithmic scale. This scale works very well when the data in question is log-linear, that is, it is distributed linearly with respect to its own logarithm. In our demonstratory case the data is linear and not logorithmic in shape, so this doesn't come out too well, but in other cases using the logorithm is the way to go. The last demo shows a power scale. This is useful for data that follows a power law distribution of some kind. Again, this doesn't work too well in our case. .. GENERATED FROM PYTHON SOURCE LINES 22-102 .. image:: /gallery/images/sphx_glr_plot_usa_city_elevations_001.png :alt: Continental US Cities by Elevation, 2016, Linear Scale, Identity Scale, Log Scale, Power Scale :class: sphx-glr-single-img .. code-block:: default import geopandas as gpd import geoplot as gplt import geoplot.crs as gcrs import numpy as np import matplotlib.pyplot as plt continental_usa_cities = gpd.read_file(gplt.datasets.get_path('usa_cities')) continental_usa_cities = continental_usa_cities.query('STATE not in ["AK", "HI", "PR"]') contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa')) proj = gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5) f, axarr = plt.subplots(2, 2, figsize=(12, 9), subplot_kw={'projection': proj}) polyplot_kwargs = {'facecolor': (0.9, 0.9, 0.9), 'linewidth': 0} pointplot_kwargs = { 'scale': 'ELEV_IN_FT', 'edgecolor': 'white', 'linewidth': 0.5, 'color': 'black' } gplt.polyplot(contiguous_usa.geometry, ax=axarr[0][0], **polyplot_kwargs) gplt.pointplot( continental_usa_cities.query("POP_2010 > 10000"), ax=axarr[0][0], limits=(0.1, 10), **pointplot_kwargs ) axarr[0][0].set_title("Linear Scale") def identity_scale(minval, maxval): def scalar(val): return 2 return scalar gplt.polyplot(contiguous_usa.geometry, ax=axarr[0][1], **polyplot_kwargs) gplt.pointplot( continental_usa_cities.query("POP_2010 > 10000"), ax=axarr[0][1], scale_func=identity_scale, **pointplot_kwargs ) axarr[0][1].set_title("Identity Scale") def log_scale(minval, maxval): def scalar(val): val = val + abs(minval) + 1 return np.log10(val) return scalar gplt.polyplot( contiguous_usa.geometry, ax=axarr[1][0], **polyplot_kwargs ) gplt.pointplot( continental_usa_cities.query("POP_2010 > 10000"), ax=axarr[1][0], scale_func=log_scale, **pointplot_kwargs ) axarr[1][0].set_title("Log Scale") def power_scale(minval, maxval): def scalar(val): val = val + abs(minval) + 1 return (val / 1000)**2 return scalar gplt.polyplot( contiguous_usa.geometry, ax=axarr[1][1], **polyplot_kwargs ) gplt.pointplot( continental_usa_cities.query("POP_2010 > 10000"), ax=axarr[1][1], scale_func=power_scale, **pointplot_kwargs ) axarr[1][1].set_title("Power Scale") plt.suptitle('Continental US Cities by Elevation, 2016', fontsize=16) plt.subplots_adjust(top=0.95) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.425 seconds) .. _sphx_glr_download_gallery_plot_usa_city_elevations.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_usa_city_elevations.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_usa_city_elevations.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_