Skip to content

Commit 6319d63

Browse files
authored
Merge pull request #940 from plotly/fix-choropleth
Fixing choropleth
2 parents a15b744 + 6a7e7f2 commit 6319d63

26 files changed

+16
-2764
lines changed

Diff for: plotly/figure_factory/_county_choropleth.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io
66
import numpy as np
7+
import os
78
import pandas as pd
89
import warnings
910

@@ -19,30 +20,33 @@
1920

2021
def _create_us_counties_df(st_to_state_name_dict, state_to_st_dict):
2122
# URLS
22-
data_url = 'plotly/package_data/data/'
23+
abs_file_path = os.path.realpath(__file__)
24+
abs_dir_path = os.path.dirname(abs_file_path)
2325

24-
shape_pre2010 = 'gz_2010_us_050_00_500k/gz_2010_us_050_00_500k.shp'
25-
shape_pre2010 = data_url + shape_pre2010
26+
abs_plotly_dir_path = abs_dir_path[:abs_dir_path.find('/figure_factory')]
27+
abs_package_data_dir_path = abs_plotly_dir_path + '/package_data/'
28+
29+
shape_pre2010 = 'gz_2010_us_050_00_500k.shp'
30+
shape_pre2010 = abs_package_data_dir_path + shape_pre2010
2631
df_shape_pre2010 = gp.read_file(shape_pre2010)
2732
df_shape_pre2010['FIPS'] = (df_shape_pre2010['STATE'] +
2833
df_shape_pre2010['COUNTY'])
2934
df_shape_pre2010['FIPS'] = pd.to_numeric(df_shape_pre2010['FIPS'])
3035

31-
states_path = 'cb_2016_us_state_500k/cb_2016_us_state_500k.shp'
32-
states_path = data_url + states_path
36+
states_path = 'cb_2016_us_state_500k.shp'
37+
states_path = abs_package_data_dir_path + states_path
3338

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

39-
county_url = 'plotly/package_data/data/cb_2016_us_county_500k/'
4044
filenames = ['cb_2016_us_county_500k.dbf',
4145
'cb_2016_us_county_500k.shp',
4246
'cb_2016_us_county_500k.shx']
4347

4448
for j in range(len(filenames)):
45-
filenames[j] = county_url + filenames[j]
49+
filenames[j] = abs_package_data_dir_path + filenames[j]
4650

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

641-
for l in np.linspace(0, 1, len(LEVELS)):
645+
for L in np.linspace(0, 1, len(LEVELS)):
642646
for idx, inter in enumerate(viri_intervals):
643-
if l == 0:
647+
if L == 0:
644648
break
645-
elif inter[0] < l <= inter[1]:
649+
elif inter[0] < L <= inter[1]:
646650
break
647651

648-
intermed = ((l - viri_intervals[idx][0]) /
652+
intermed = ((L - viri_intervals[idx][0]) /
649653
(viri_intervals[idx][1] - viri_intervals[idx][0]))
650654

651655
float_color = colors.find_intermediate_color(

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.cpg

-1
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.prj

-1
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.shp

100755100644
File mode changed.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.shp.ea.iso.xml

-404
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.shp.iso.xml

-539
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.shp.xml

-410
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_county_500k/cb_2016_us_county_500k.shx

100755100644
File mode changed.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_state_500k/cb_2016_us_state_500k.cpg

-1
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_state_500k/cb_2016_us_state_500k.prj

-1
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_state_500k/cb_2016_us_state_500k.shp.ea.iso.xml

-335
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_state_500k/cb_2016_us_state_500k.shp.iso.xml

-501
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/cb_2016_us_state_500k/cb_2016_us_state_500k.shp.xml

-329
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/gz_2010_us_050_00_500k/gz_2010_us_050_00_500k.prj

-1
This file was deleted.

Diff for: plotly/tests/test_optional/test_figure_factory/plotly/package_data/data/gz_2010_us_050_00_500k/gz_2010_us_050_00_500k.xml

-229
This file was deleted.

Diff for: plotly/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.4.0'
1+
__version__ = '2.4.1'

0 commit comments

Comments
 (0)