Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8c7eb17

Browse filesBrowse files
authored
Merge pull request plotly#947 from plotly/offline_mode_choropleth
choropleth improvements
2 parents 8e7c112 + fbaaba2 commit 8c7eb17
Copy full SHA for 8c7eb17

File tree

Expand file treeCollapse file tree

13 files changed

+35
-33
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+35
-33
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
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.5.0] - UNRELEASED
6+
### Updated
7+
- `plotly.figure_factory.create_choropleth` has changed some of the default plotting options:
8+
- 'offline_mode' param has been removed from call signature
9+
- persistent selection api for the centroid points is automatically enabled. See https://plot.ly/python/reference/#scatter-selected and https://plot.ly/python/reference/#scatter-unselected for details
10+
- FIPS values that appear on hover are 0-padded to ensure they are 5 digits
11+
- for the county lines data `hover_info='none'` by default
12+
513
## [2.4.1] - 2018-02-21
614
### Fixed
715
- The required shapefiles to generate the choropleths via `plotly.figure_factory.create_choropleth` are now shipped in the package data.

‎circle.yml

Copy file name to clipboardExpand all lines: circle.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ machine:
1212

1313
node:
1414
# use a pre-installed version of node so we don't need to download it.
15-
version: 4.2.2
15+
version: 6.0.0
1616

1717
dependencies:
1818

‎plotly/figure_factory/_county_choropleth.py

Copy file name to clipboardExpand all lines: plotly/figure_factory/_county_choropleth.py
+25-31Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ def _intervals_as_labels(array_of_intervals, round_legend_values, exponent_forma
300300
def _calculations(df, fips, values, index, f, simplify_county, level,
301301
x_centroids, y_centroids, centroid_text, x_traces,
302302
y_traces, fips_polygon_map):
303+
# 0-pad FIPS code to ensure exactly 5 digits
304+
padded_f = str(f).zfill(5)
303305
if fips_polygon_map[f].type == 'Polygon':
304306
x = fips_polygon_map[f].simplify(
305307
simplify_county
@@ -311,10 +313,11 @@ def _calculations(df, fips, values, index, f, simplify_county, level,
311313
x_c, y_c = fips_polygon_map[f].centroid.xy
312314
county_name_str = str(df[df['FIPS'] == f]['COUNTY_NAME'].iloc[0])
313315
state_name_str = str(df[df['FIPS'] == f]['STATE_NAME'].iloc[0])
316+
314317
t_c = (
315318
'County: ' + county_name_str + '<br>' +
316319
'State: ' + state_name_str + '<br>' +
317-
'FIPS: ' + str(f) + '<br>Value: ' + str(values[index])
320+
'FIPS: ' + padded_f + '<br>Value: ' + str(values[index])
318321
)
319322

320323
x_centroids.append(x_c[0])
@@ -337,7 +340,7 @@ def _calculations(df, fips, values, index, f, simplify_county, level,
337340
text = (
338341
'County: ' + county_name_str + '<br>' +
339342
'State: ' + state_name_str + '<br>' +
340-
'FIPS: ' + str(f) + '<br>Value: ' + str(values[index])
343+
'FIPS: ' + padded_f + '<br>Value: ' + str(values[index])
341344
)
342345
t_c = [text for poly in fips_polygon_map[f]]
343346
x_centroids = x_c + x_centroids
@@ -352,12 +355,11 @@ def _calculations(df, fips, values, index, f, simplify_county, level,
352355

353356
def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
354357
colorscale=None, order=None, simplify_county=0.02,
355-
simplify_state=0.02, asp=None, offline_mode=False,
356-
show_hover=True, show_state_data=True,
357-
state_outline=None, county_outline=None,
358-
centroid_marker=None, round_legend_values=False,
359-
exponent_format=False, legend_title='',
360-
**layout_options):
358+
simplify_state=0.02, asp=None, show_hover=True,
359+
show_state_data=True, state_outline=None,
360+
county_outline=None, centroid_marker=None,
361+
round_legend_values=False, exponent_format=False,
362+
legend_title='', **layout_options):
361363
"""
362364
Returns figure for county choropleth. Uses data from package_data.
363365
@@ -399,12 +401,6 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
399401
Default = 0.02
400402
:param (float) asp: the width-to-height aspect ratio for the camera.
401403
Default = 2.5
402-
:param (bool) offline_mode: if set to True, the centroids of each county
403-
are invisible until selected over with a dragbox. Warning: this can
404-
only be used if you are plotting in offline mode with validate set to
405-
False as the params that are being added to the fig dictionary are not
406-
yet part of the plotly.py python library. Stay tuned for updates.
407-
Default = False
408404
:param (bool) show_hover: show county hover and centroid info
409405
:param (bool) show_state_data: reveals state boundary lines
410406
:param (dict) state_outline: dict of attributes of the state outline
@@ -416,8 +412,9 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
416412
https://plot.ly/python/reference/#scatter-marker-line for all valid
417413
params
418414
:param (dict) centroid_marker: dict of attributes of the centroid marker.
419-
See https://plot.ly/python/reference/#scatter-marker for all valid
420-
params
415+
The centroid markers are invisible by default and appear visible on
416+
selection. See https://plot.ly/python/reference/#scatter-marker for
417+
all valid params
421418
:param (bool) round_legend_values: automatically round the numbers that
422419
appear in the legend to the nearest integer.
423420
Default = False
@@ -587,9 +584,11 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
587584
county_outline = {'color': 'rgb(0, 0, 0)',
588585
'width': 0}
589586
if not centroid_marker:
590-
centroid_marker = {'size': 2,
591-
'color': 'rgb(255, 255, 255)',
592-
'opacity': 0}
587+
centroid_marker = {'size': 3, 'color': 'white', 'opacity': 1}
588+
589+
# ensure centroid markers appear on selection
590+
if 'opacity' not in centroid_marker:
591+
centroid_marker.update({'opacity': 1})
593592

594593
if len(fips) != len(values):
595594
raise exceptions.PlotlyError(
@@ -788,7 +787,7 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
788787
fill='toself',
789788
fillcolor=color_lookup[lev],
790789
name=lev,
791-
hoverinfo='text',
790+
hoverinfo='none',
792791
)
793792
plot_data.append(county_data)
794793

@@ -802,19 +801,14 @@ def create_choropleth(fips, values, scope=['usa'], binning_endpoints=None,
802801
text=centroid_text,
803802
name='US Counties',
804803
mode='markers',
805-
marker=centroid_marker,
804+
marker={'color': 'white', 'opacity': 0},
806805
hoverinfo='text'
807806
)
808-
if offline_mode:
809-
centroids_on_select = dict(
810-
selected=dict(
811-
marker=dict(size=2, color='white', opacity=1)
812-
),
813-
unselected=dict(
814-
marker=dict(opacity=0)
815-
)
816-
)
817-
hover_points.update(centroids_on_select)
807+
centroids_on_select = dict(
808+
selected=dict(marker=centroid_marker),
809+
unselected=dict(marker=dict(opacity=0))
810+
)
811+
hover_points.update(centroids_on_select)
818812
plot_data.append(hover_points)
819813

820814
if show_state_data:

‎plotly/version.py

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.4.1'
1+
__version__ = '2.5.0'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.