Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Readme.md

Choropleth Graphs

Choropleth graphs are maps with coloured areas to display the values to each geo location. Plotly's Choropleth Graph supports various maps, including the world and the US. In this folder, we will go over how to create chropleth graphs with Python and Plotly.

Files

The following scripts are used in this chapter:

  • Example_Basic_ChoroplethGraph.py

Pacakges Needed

This chapter requires the following packages for the scripts used:

  • Pandas
  • Plotly

Data Used

This chapter may use the following data from the Data folder:

  • county_avg_rent.csv
  • countyfips.csv

countyfips.csv

Plotly has a feature to draw borders based on FIPS (Federal Information Processing Standards) defined by the US government, so Plotly could draw the border automatically if you have connected the data with FIPS. countyfips.csv is the table for all FIPS number for all counties in the US.

Syntax

Approach 1 - figure_factory.create_choropleth()

figure_factory.create_choropleth() is a easy way to create choropleth graphs in the United States, especially only displaying individual state. Different with the go.Figure(), figure_factory.create_choropleth() takes all data parameters and layout parameters.

figure_factory.create_choropleth() has the following parameters:

  • fips: FIPS (Federal Information Processing Standards) defined by the US government, an attribute to locate the counties in United States
  • values: Values
  • colorscale: The set of colours to display the value of each area, see plotly.colors.sequential for colour sets
  • show_state_data: (Coming Soon...)
  • scope: The map used in the visualization
  • binning_endpoints: To map the range of values to colorscale
  • county_outline (Dictionary): Define the lines on county borders
    • color: Color of county borders, RGB or Hex in string
    • width: The width of borderline in px, integer
  • state_outline (Dictionary): Define the lines on state borders
    • color: Color of county borders, RGB or Hex in string
    • width: The width of borderline in px, integer

Choropleth Graph Exclusive parameters:

  • fips: FIPS (Federal Information Processing Standards) defined by the US government, an attribute to locate the counties in United States
  • show_state_data: (Coming Soon...)
  • scope: The map used in the visualization
  • binning_endpoints: To map the range of values to colorscale
  • county_outline (Dictionary): Define the lines on county borders
    • color: Color of county borders, RGB or Hex in string
    • width: The width of borderline in px, integer
  • state_outline (Dictionary): Define the lines on state borders
    • color: Color of county borders, RGB or Hex in string
    • width: The width of borderline in px, integer

Examples

Example 1 - Using figure_factory.create_choropleth()

# Define the endpoints 
endpts = list(range(1,6))

fig = ff.create_choropleth(
	  fips = df['fips'], values = df['median_sqft_price'], 
	  colorscale = plotly.colors.sequential.Oranges,
	  show_state_data = True, scope = ['CA'],
	  binning_endpoints=endpts,
	  county_outline={'color': 'rgb(15,15,55)', 'width': 1},
	  state_outline={'color': 'rgb(15,15,55)', 'width': 1},
	  legend_title='Median Rent')

Reference

Plotly Documentation Choropleth Graph