Skip to content

Commit 1fb2547

Browse files
authored
Merge pull request #929 from plotly/zipcode-choro
Choropleth Counties
2 parents f761e2a + 7c47e94 commit 1fb2547

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+19385
-9305
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.4.0] - 2018-02-16
6+
### Added
7+
- County Choropleth figure factory. Call `help(plotly.figure_factory.create_choropleth)` for examples and how to get started making choropleths of US counties with the Python API.
8+
9+
510
## [2.3.0] - 2018-01-25
611
### Fixed
712
- Merged [pull request](https://github.com/plotly/plotly.py/commit/a226e07393c158e01c34c050aaf492da9d77679a) that fixes `GraphWidget` for IPython > v6

optional-requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ scipy
2828
## jupyter ##
2929
jupyter
3030
ipykernel
31+
32+
## deps for _county_choropleth.py figure factory
33+
pyshp
34+
geopandas
35+
shapely

plotly/colors.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,60 @@
1818
floats between 0 and 1 inclusive.
1919
2020
-----
21-
Types of colormap:
21+
Colormaps and Colorscales:
22+
A colormap or a colorscale is a correspondence between values - Pythonic
23+
objects such as strings and floats - to colors.
24+
2225
There are typically two main types of colormaps that exist: numerical and
2326
categorical colormaps.
2427
25-
Numerical colormaps are used when a the coloring column being used takes a
26-
spectrum of values or numbers. Alternatively, a categorical colormap is used
27-
to assign a specific value in a color column to a specific color everytime it
28-
appears in the plot at hand. For instance, a column of strings in a dataframe
29-
would naturally use a categorical colormap. You can choose however to use a
30-
categorical colormap with a column of numbers. Be careful though, as if you
31-
have a large set of unique numbers in your column you'll get a lot of colors.
32-
28+
Numerical:
29+
----------
30+
Numerical colormaps are used when the coloring column being used takes a
31+
spectrum of values or numbers.
32+
33+
A classic example from the Plotly library:
34+
```
35+
rainbow_colorscale = [
36+
[0, 'rgb(150,0,90)'], [0.125, 'rgb(0,0,200)'],
37+
[0.25, 'rgb(0,25,255)'], [0.375, 'rgb(0,152,255)'],
38+
[0.5, 'rgb(44,255,150)'], [0.625, 'rgb(151,255,0)'],
39+
[0.75, 'rgb(255,234,0)'], [0.875, 'rgb(255,111,0)'],
40+
[1, 'rgb(255,0,0)']
41+
]
42+
```
43+
44+
Notice that this colorscale is a list of lists with each inner list containing
45+
a number and a color. These left hand numbers in the nested lists go from 0 to
46+
1, and they are like pointers tell you when a number is mapped to a specific
47+
color.
48+
49+
If you have a column of numbers `col_num` that you want to plot, and you know
50+
51+
```
52+
min(col_num) = 0
53+
max(col_num) = 100
54+
```
55+
56+
then if you pull out the number `12.5` in the list and want to figure out what
57+
color the corresponding chart element (bar, scatter plot, etc) is going to be,
58+
you'll figure out that proportionally 12.5 to 100 is the same as 0.125 to 1.
59+
So, the point will be mapped to 'rgb(0,0,200)'.
60+
61+
All other colors between the pinned values in a colorscale are linearly
62+
interpolated.
63+
64+
Categorical:
65+
------------
66+
Alternatively, a categorical colormap is used to assign a specific value in a
67+
color column to a specific color everytime it appears in the dataset.
68+
69+
A column of strings in a panadas.dataframe that is chosen to serve as the
70+
color index would naturally use a categorical colormap. However, you can
71+
choose to use a categorical colormap with a column of numbers.
72+
73+
Be careful! If you have a lot of unique numbers in your color column you will
74+
end up with a colormap that is massive and may slow down graphing performance.
3375
"""
3476
from __future__ import absolute_import
3577

plotly/figure_factory/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
from plotly.figure_factory._table import create_table
1919
from plotly.figure_factory._trisurf import create_trisurf
2020
from plotly.figure_factory._violin import create_violin
21+
from plotly.figure_factory._county_choropleth import create_choropleth

0 commit comments

Comments
 (0)