Skip to content

Choropleth Counties #929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b18aa27
added us shapefiles
Kully Jan 15, 2018
472b8dc
importing package_data
Kully Jan 15, 2018
223cdf6
revert adding data to package_data
Kully Jan 16, 2018
b43a906
added county FF file
Kully Jan 25, 2018
9575bd5
add county_choropleth to __init__
Kully Jan 25, 2018
ae3d339
add data folder
Kully Jan 25, 2018
9981524
scatter to scattergl test
Kully Jan 26, 2018
c60198e
merged master
Kully Jan 26, 2018
afb1318
rewrite help(plotly.colors) doc for clarity and colormap def
Kully Jan 29, 2018
0d68780
syntax and pep 8 and doc string
Kully Jan 29, 2018
81d0859
simplifications and other stuff - works
Kully Jan 31, 2018
a675218
added is_sequence function to utils in ff
Kully Jan 31, 2018
b892935
PRE_REFACTOR
Kully Jan 31, 2018
b5f1f84
updated changelog and most of choropleth works - viridis as default c…
Kully Feb 9, 2018
e5fb4ac
added files for county shapefile generation
Kully Feb 9, 2018
184b060
bump ver - nearly done
Kully Feb 12, 2018
9450024
make update_default_schema
Kully Feb 12, 2018
e1858ca
fixing...
Kully Feb 13, 2018
9513234
finished tests -ready
Kully Feb 13, 2018
a348be0
fix broken code
Kully Feb 13, 2018
dad9db3
shapely op import
Kully Feb 13, 2018
9db1e35
update optional req
Kully Feb 13, 2018
ccbbb5d
update optional req for pyshp
Kully Feb 13, 2018
be825a2
comment rewrite
Kully Feb 13, 2018
a007525
version correction and added state/county names in dataframe
Kully Feb 13, 2018
c1f34f4
add new figure_factory folder and finished chelsea's 1st round of com…
Kully Feb 13, 2018
0b55bfc
only use gp and opt imports if they are not NoneType
Kully Feb 14, 2018
0740fa9
deleted duplicate test_figure_factory in favour of one in dir with sa…
Kully Feb 14, 2018
6ee69a2
add optional req to test env
Kully Feb 14, 2018
1079833
syntax error in tox.ini
Kully Feb 14, 2018
3b9412a
make update_default_schema
Kully Feb 14, 2018
7eb02e7
print statements for import error
Kully Feb 14, 2018
fab5f1a
added pyshp in installation for tox.ini
Kully Feb 14, 2018
02a3b9f
remove print statements
Kully Feb 14, 2018
e61f88b
fixed py2/3 io.open
Kully Feb 16, 2018
0dc8e75
remove unneeded files
Kully Feb 16, 2018
c35b39d
remove ALL unnecessary files
Kully Feb 16, 2018
1927e8d
fix module import error to include pip commands to execute
Kully Feb 16, 2018
7c47e94
update version number and release date in changelog
Kully Feb 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [2.4.0] - 2018-02-16
### Added
- 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.


## [2.3.0] - 2018-01-25
### Fixed
- Merged [pull request](https://github.com/plotly/plotly.py/commit/a226e07393c158e01c34c050aaf492da9d77679a) that fixes `GraphWidget` for IPython > v6
Expand Down
5 changes: 5 additions & 0 deletions optional-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ scipy
## jupyter ##
jupyter
ipykernel

## deps for _county_choropleth.py figure factory
pyshp
geopandas
shapely
60 changes: 51 additions & 9 deletions plotly/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,60 @@
floats between 0 and 1 inclusive.

-----
Types of colormap:
Colormaps and Colorscales:
A colormap or a colorscale is a correspondence between values - Pythonic
objects such as strings and floats - to colors.

There are typically two main types of colormaps that exist: numerical and
categorical colormaps.

Numerical colormaps are used when a the coloring column being used takes a
spectrum of values or numbers. Alternatively, a categorical colormap is used
to assign a specific value in a color column to a specific color everytime it
appears in the plot at hand. For instance, a column of strings in a dataframe
would naturally use a categorical colormap. You can choose however to use a
categorical colormap with a column of numbers. Be careful though, as if you
have a large set of unique numbers in your column you'll get a lot of colors.

Numerical:
----------
Numerical colormaps are used when the coloring column being used takes a
spectrum of values or numbers.

A classic example from the Plotly library:
```
rainbow_colorscale = [
[0, 'rgb(150,0,90)'], [0.125, 'rgb(0,0,200)'],
[0.25, 'rgb(0,25,255)'], [0.375, 'rgb(0,152,255)'],
[0.5, 'rgb(44,255,150)'], [0.625, 'rgb(151,255,0)'],
[0.75, 'rgb(255,234,0)'], [0.875, 'rgb(255,111,0)'],
[1, 'rgb(255,0,0)']
]
```

Notice that this colorscale is a list of lists with each inner list containing
a number and a color. These left hand numbers in the nested lists go from 0 to
1, and they are like pointers tell you when a number is mapped to a specific
color.

If you have a column of numbers `col_num` that you want to plot, and you know

```
min(col_num) = 0
max(col_num) = 100
```

then if you pull out the number `12.5` in the list and want to figure out what
color the corresponding chart element (bar, scatter plot, etc) is going to be,
you'll figure out that proportionally 12.5 to 100 is the same as 0.125 to 1.
So, the point will be mapped to 'rgb(0,0,200)'.

All other colors between the pinned values in a colorscale are linearly
interpolated.

Categorical:
------------
Alternatively, a categorical colormap is used to assign a specific value in a
color column to a specific color everytime it appears in the dataset.

A column of strings in a panadas.dataframe that is chosen to serve as the
color index would naturally use a categorical colormap. However, you can
choose to use a categorical colormap with a column of numbers.

Be careful! If you have a lot of unique numbers in your color column you will
end up with a colormap that is massive and may slow down graphing performance.
"""
from __future__ import absolute_import

Expand Down
1 change: 1 addition & 0 deletions plotly/figure_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
from plotly.figure_factory._table import create_table
from plotly.figure_factory._trisurf import create_trisurf
from plotly.figure_factory._violin import create_violin
from plotly.figure_factory._county_choropleth import create_choropleth
Loading