Skip to content
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

Fixing choropleth #940

Merged
merged 5 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 15 additions & 11 deletions plotly/figure_factory/_county_choropleth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io
import numpy as np
import os
import pandas as pd
import warnings

Expand All @@ -19,30 +20,33 @@

def _create_us_counties_df(st_to_state_name_dict, state_to_st_dict):
# URLS
data_url = 'plotly/package_data/data/'
abs_file_path = os.path.realpath(__file__)
abs_dir_path = os.path.dirname(abs_file_path)

shape_pre2010 = 'gz_2010_us_050_00_500k/gz_2010_us_050_00_500k.shp'
shape_pre2010 = data_url + shape_pre2010
abs_plotly_dir_path = abs_dir_path[:abs_dir_path.find('/figure_factory')]
abs_package_data_dir_path = abs_plotly_dir_path + '/package_data/'

shape_pre2010 = 'gz_2010_us_050_00_500k.shp'
shape_pre2010 = abs_package_data_dir_path + shape_pre2010
df_shape_pre2010 = gp.read_file(shape_pre2010)
df_shape_pre2010['FIPS'] = (df_shape_pre2010['STATE'] +
df_shape_pre2010['COUNTY'])
df_shape_pre2010['FIPS'] = pd.to_numeric(df_shape_pre2010['FIPS'])

states_path = 'cb_2016_us_state_500k/cb_2016_us_state_500k.shp'
states_path = data_url + states_path
states_path = 'cb_2016_us_state_500k.shp'
states_path = abs_package_data_dir_path + states_path

# state df
df_state = gp.read_file(states_path)
df_state = df_state[['STATEFP', 'NAME', 'geometry']]
df_state = df_state.rename(columns={'NAME': 'STATE_NAME'})

county_url = 'plotly/package_data/data/cb_2016_us_county_500k/'
filenames = ['cb_2016_us_county_500k.dbf',
'cb_2016_us_county_500k.shp',
'cb_2016_us_county_500k.shx']

for j in range(len(filenames)):
filenames[j] = county_url + filenames[j]
filenames[j] = abs_package_data_dir_path + filenames[j]

dbf = io.open(filenames[0], 'rb')
shp = io.open(filenames[1], 'rb')
Expand Down Expand Up @@ -638,14 +642,14 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
list(np.linspace(0, 1, viri_len))
)[1:-1]

for l in np.linspace(0, 1, len(LEVELS)):
for L in np.linspace(0, 1, len(LEVELS)):
for idx, inter in enumerate(viri_intervals):
if l == 0:
if L == 0:
break
elif inter[0] < l <= inter[1]:
elif inter[0] < L <= inter[1]:
break

intermed = ((l - viri_intervals[idx][0]) /
intermed = ((L - viri_intervals[idx][0]) /
(viri_intervals[idx][1] - viri_intervals[idx][0]))

float_color = colors.find_intermediate_color(
Expand Down

This file was deleted.

Binary file not shown.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion plotly/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.4.0'
__version__ = '2.4.1'