.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_obesity.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_obesity.py: Cartogram of US states by obesity rate ====================================== This example ``cartogram`` showcases regional trends for obesity in the United States. Rugged mountain states are the healthiest; the deep South, the unhealthiest. This example inspired by the `"Non-Contiguous Cartogram" `_ example in the D3.JS example gallery. .. GENERATED FROM PYTHON SOURCE LINES 11-41 .. image:: /gallery/images/sphx_glr_plot_obesity_001.png :alt: Adult Obesity Rate by State, 2013 :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Text(0.5, 1.0, 'Adult Obesity Rate by State, 2013') | .. code-block:: default import pandas as pd import geopandas as gpd import geoplot as gplt import geoplot.crs as gcrs import matplotlib.pyplot as plt import mapclassify as mc # load the data obesity_by_state = pd.read_csv(gplt.datasets.get_path('obesity_by_state'), sep='\t') contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa')) contiguous_usa['Obesity Rate'] = contiguous_usa['state'].map( lambda state: obesity_by_state.query("State == @state").iloc[0]['Percent'] ) scheme = mc.Quantiles(contiguous_usa['Obesity Rate'], k=5) ax = gplt.cartogram( contiguous_usa, scale='Obesity Rate', limits=(0.75, 1), projection=gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5), hue='Obesity Rate', cmap='Reds', scheme=scheme, linewidth=0.5, legend=True, legend_kwargs={'loc': 'lower right'}, legend_var='hue', figsize=(12, 7) ) gplt.polyplot(contiguous_usa, facecolor='lightgray', edgecolor='None', ax=ax) plt.title("Adult Obesity Rate by State, 2013") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.625 seconds) .. _sphx_glr_download_gallery_plot_obesity.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_obesity.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_obesity.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_