From dd577a0a7b164ec9f3dec1648d07964eaed72c30 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Fri, 29 Nov 2019 15:23:39 -0500 Subject: [PATCH 1/8] add choropleth_mapbox to px --- .../python/plotly/plotly/express/__init__.py | 2 + .../plotly/plotly/express/_chart_types.py | 38 ++++++++++++++++++- .../python/plotly/plotly/express/_core.py | 8 +++- packages/python/plotly/plotly/express/_doc.py | 4 ++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/python/plotly/plotly/express/__init__.py b/packages/python/plotly/plotly/express/__init__.py index c825233aca..4a07c7676f 100644 --- a/packages/python/plotly/plotly/express/__init__.py +++ b/packages/python/plotly/plotly/express/__init__.py @@ -44,6 +44,7 @@ treemap, funnel, funnel_area, + choropleth_mapbox, ) from ._imshow import imshow @@ -82,6 +83,7 @@ "strip", "histogram", "choropleth", + "choropleth_mapbox", "pie", "sunburst", "treemap", diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index 8cbd4d85b6..f35a0f62e0 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -842,7 +842,6 @@ def choropleth( hover_name=None, hover_data=None, custom_data=None, - size=None, animation_frame=None, animation_group=None, category_orders={}, @@ -850,7 +849,6 @@ def choropleth( color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, - size_max=None, projection=None, scope=None, center=None, @@ -998,6 +996,42 @@ def scatter_mapbox( scatter_mapbox.__doc__ = make_docstring(scatter_mapbox) +def choropleth_mapbox( + data_frame=None, + geojson=None, + locations=None, + color=None, + hover_name=None, + hover_data=None, + custom_data=None, + animation_frame=None, + animation_group=None, + category_orders={}, + labels={}, + color_continuous_scale=None, + range_color=None, + color_continuous_midpoint=None, + opacity=None, + zoom=None, + title=None, + template=None, + width=None, + height=None, +): + """ + In a Mapbox choropleth map, each row of `data_frame` is represented by a + colored region on a Mapbox map. + """ + return make_figure( + args=locals(), + constructor=go.Choroplethmapbox, + trace_patch=dict(geojson=geojson), + ) + + +choropleth_mapbox.__doc__ = make_docstring(choropleth_mapbox) + + def line_mapbox( data_frame=None, lat=None, diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 459168ea02..9cfd4c7f7f 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -287,7 +287,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref): v_label_col = get_decorated_label(args, col, None) mapping_labels[v_label_col] = "%%{customdata[%d]}" % (position) elif k == "color": - if trace_spec.constructor == go.Choropleth: + if trace_spec.constructor in [go.Choropleth, go.Choroplethmapbox]: result["z"] = g[v] result["coloraxis"] = "coloraxis1" mapping_labels[v_label] = "%{z}" @@ -380,6 +380,7 @@ def configure_axes(args, constructor, fig, orders): go.Scatterpolargl: configure_polar_axes, go.Barpolar: configure_polar_axes, go.Scattermapbox: configure_mapbox, + go.Choroplethmapbox: configure_mapbox, go.Scattergeo: configure_geo, go.Choropleth: configure_geo, } @@ -569,7 +570,9 @@ def configure_mapbox(args, fig, orders): center=dict( lat=args["data_frame"][args["lat"]].mean(), lon=args["data_frame"][args["lon"]].mean(), - ), + ) + if "lat" in args and "lon" in args + else dict(), zoom=args["zoom"], ) ) @@ -1221,6 +1224,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): go.Parcats, go.Parcoords, go.Choropleth, + go.Choroplethmapbox, go.Histogram2d, go.Sunburst, go.Treemap, diff --git a/packages/python/plotly/plotly/express/_doc.py b/packages/python/plotly/plotly/express/_doc.py index c1d015cbe3..c831af4a80 100644 --- a/packages/python/plotly/plotly/express/_doc.py +++ b/packages/python/plotly/plotly/express/_doc.py @@ -456,6 +456,10 @@ ], box=["boolean (default `False`)", "If `True`, boxes are drawn inside the violins."], notched=["boolean (default `False`)", "If `True`, boxes are drawn with notches."], + geojson=[ + "GeoJSON-formatted dict", + "Must contain a Polygon feature collection, with IDs, which are references from `locations`.", + ], cumulative=[ "boolean (default `False`)", "If `True`, histogram values are cumulative.", From d2cec8f1dfa384ddf2afd8bd5ebe3dd4380ea93d Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 30 Nov 2019 21:11:45 -0500 Subject: [PATCH 2/8] px.density_mapbox --- .../python/plotly/plotly/express/__init__.py | 5 +-- .../plotly/plotly/express/_chart_types.py | 35 +++++++++++++++++++ .../python/plotly/plotly/express/_core.py | 10 +++--- packages/python/plotly/plotly/express/_doc.py | 5 +++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/python/plotly/plotly/express/__init__.py b/packages/python/plotly/plotly/express/__init__.py index 4a07c7676f..eec2fd9da1 100644 --- a/packages/python/plotly/plotly/express/__init__.py +++ b/packages/python/plotly/plotly/express/__init__.py @@ -4,6 +4,7 @@ """ from __future__ import absolute_import from plotly import optional_imports +from ._imshow import imshow pd = optional_imports.get_module("pandas") if pd is None: @@ -12,7 +13,6 @@ Plotly express requires pandas to be installed.""" ) - from ._chart_types import ( # noqa: F401 scatter, scatter_3d, @@ -45,9 +45,9 @@ funnel, funnel_area, choropleth_mapbox, + density_mapbox, ) -from ._imshow import imshow from ._core import ( # noqa: F401 set_mapbox_access_token, @@ -67,6 +67,7 @@ "scatter_matrix", "density_contour", "density_heatmap", + "density_mapbox", "line", "line_3d", "line_polar", diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index f35a0f62e0..4dcd3acd14 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1032,6 +1032,41 @@ def choropleth_mapbox( choropleth_mapbox.__doc__ = make_docstring(choropleth_mapbox) +def density_mapbox( + data_frame=None, + lat=None, + lon=None, + z=None, + hover_name=None, + hover_data=None, + custom_data=None, + animation_frame=None, + animation_group=None, + category_orders={}, + labels={}, + color_continuous_scale=None, + range_color=None, + color_continuous_midpoint=None, + opacity=None, + zoom=8, + radius=None, + title=None, + template=None, + width=None, + height=None, +): + """ + In a Mapbox density map, each row of `data_frame` contributes to the intensity of + the color of the region around the corresponding point on the map + """ + return make_figure( + args=locals(), constructor=go.Densitymapbox, trace_patch=dict(radius=radius) + ) + + +density_mapbox.__doc__ = make_docstring(density_mapbox) + + def line_mapbox( data_frame=None, lat=None, diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 9cfd4c7f7f..6d57a4ef8c 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -381,6 +381,7 @@ def configure_axes(args, constructor, fig, orders): go.Barpolar: configure_polar_axes, go.Scattermapbox: configure_mapbox, go.Choroplethmapbox: configure_mapbox, + go.Densitymapbox: configure_mapbox, go.Scattergeo: configure_geo, go.Choropleth: configure_geo, } @@ -571,7 +572,7 @@ def configure_mapbox(args, fig, orders): lat=args["data_frame"][args["lat"]].mean(), lon=args["data_frame"][args["lon"]].mean(), ) - if "lat" in args and "lon" in args + if "lat" in args and "lon" in args else dict(), zoom=args["zoom"], ) @@ -1012,7 +1013,7 @@ def infer_config(args, constructor, trace_patch): attrables = ( ["x", "y", "z", "a", "b", "c", "r", "theta", "size", "dimensions"] + ["custom_data", "hover_name", "hover_data", "text"] - + ["names", "values", "parents", "ids"] + + ["names", "values", "parents", "ids", "radius"] + ["error_x", "error_x_minus"] + ["error_y", "error_y_minus", "error_z", "error_z_minus"] + ["lat", "lon", "locations", "animation_group"] @@ -1086,7 +1087,7 @@ def infer_config(args, constructor, trace_patch): # Compute final trace patch trace_patch = trace_patch.copy() - if constructor == go.Histogram2d: + if constructor in [go.Histogram2d, go.Densitymapbox]: show_colorbar = True trace_patch["coloraxis"] = "coloraxis1" @@ -1225,6 +1226,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): go.Parcoords, go.Choropleth, go.Choroplethmapbox, + go.Densitymapbox, go.Histogram2d, go.Sunburst, go.Treemap, @@ -1325,7 +1327,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): ) layout_patch = layout_patch.copy() if show_colorbar: - colorvar = "z" if constructor == go.Histogram2d else "color" + colorvar = "z" if constructor in [go.Histogram2d, go.Densitymapbox] else "color" range_color = args["range_color"] or [None, None] colorscale_validator = ColorscaleValidator("colorscale", "make_figure") diff --git a/packages/python/plotly/plotly/express/_doc.py b/packages/python/plotly/plotly/express/_doc.py index c831af4a80..dae2b77475 100644 --- a/packages/python/plotly/plotly/express/_doc.py +++ b/packages/python/plotly/plotly/express/_doc.py @@ -164,6 +164,11 @@ colref_desc, "Values from this column or array_like are used to assign mark sizes.", ], + radius=[ + colref_type, + colref_desc, + "Values from this column or array_like are used to set the radius of influence of each point.", + ], hover_name=[ colref_type, colref_desc, From 34ef100293b2100699d9669bc6b640c3fe7f34eb Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 30 Nov 2019 21:41:40 -0500 Subject: [PATCH 3/8] rounding out mapbox functions --- .../plotly/plotly/express/_chart_types.py | 8 ++- .../python/plotly/plotly/express/_core.py | 50 +++++++++---------- packages/python/plotly/plotly/express/_doc.py | 12 +++-- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index 4dcd3acd14..4ac3cc3956 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -981,6 +981,8 @@ def scatter_mapbox( opacity=None, size_max=None, zoom=8, + center=None, + mapbox_style=None, title=None, template=None, width=None, @@ -1012,7 +1014,9 @@ def choropleth_mapbox( range_color=None, color_continuous_midpoint=None, opacity=None, - zoom=None, + zoom=8, + center=None, + mapbox_style=None, title=None, template=None, width=None, @@ -1049,6 +1053,8 @@ def density_mapbox( color_continuous_midpoint=None, opacity=None, zoom=8, + center=None, + mapbox_style=None, radius=None, title=None, template=None, diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 6d57a4ef8c..1cecba9ba8 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -504,13 +504,11 @@ def configure_cartesian_axes(args, fig, orders): def configure_ternary_axes(args, fig, orders): - fig.update( - layout=dict( - ternary=dict( - aaxis=dict(title=get_label(args, args["a"])), - baxis=dict(title=get_label(args, args["b"])), - caxis=dict(title=get_label(args, args["c"])), - ) + fig.update_layout( + ternary=dict( + aaxis=dict(title=get_label(args, args["a"])), + baxis=dict(title=get_label(args, args["b"])), + caxis=dict(title=get_label(args, args["c"])), ) ) @@ -564,30 +562,28 @@ def configure_3d_axes(args, fig, orders): def configure_mapbox(args, fig, orders): - fig.update( - layout=dict( - mapbox=dict( - accesstoken=MAPBOX_TOKEN, - center=dict( - lat=args["data_frame"][args["lat"]].mean(), - lon=args["data_frame"][args["lon"]].mean(), - ) - if "lat" in args and "lon" in args - else dict(), - zoom=args["zoom"], - ) + center = args["center"] + if not center and "lat" in args and "lon" in args: + center = dict( + lat=args["data_frame"][args["lat"]].mean(), + lon=args["data_frame"][args["lon"]].mean(), + ) + fig.update_layout( + mapbox=dict( + accesstoken=MAPBOX_TOKEN, + center=center, + zoom=args["zoom"], + style=args["mapbox_style"], ) ) def configure_geo(args, fig, orders): - fig.update( - layout=dict( - geo=dict( - center=args["center"], - scope=args["scope"], - projection=dict(type=args["projection"]), - ) + fig.update_layout( + geo=dict( + center=args["center"], + scope=args["scope"], + projection=dict(type=args["projection"]), ) ) @@ -1013,7 +1009,7 @@ def infer_config(args, constructor, trace_patch): attrables = ( ["x", "y", "z", "a", "b", "c", "r", "theta", "size", "dimensions"] + ["custom_data", "hover_name", "hover_data", "text"] - + ["names", "values", "parents", "ids", "radius"] + + ["names", "values", "parents", "ids"] + ["error_x", "error_x_minus"] + ["error_y", "error_y_minus", "error_z", "error_z_minus"] + ["lat", "lon", "locations", "animation_group"] diff --git a/packages/python/plotly/plotly/express/_doc.py b/packages/python/plotly/plotly/express/_doc.py index dae2b77475..ae9d42b229 100644 --- a/packages/python/plotly/plotly/express/_doc.py +++ b/packages/python/plotly/plotly/express/_doc.py @@ -164,11 +164,7 @@ colref_desc, "Values from this column or array_like are used to assign mark sizes.", ], - radius=[ - colref_type, - colref_desc, - "Values from this column or array_like are used to set the radius of influence of each point.", - ], + radius=["int (default is 30)", "Sets the radius of influence of each point.",], hover_name=[ colref_type, colref_desc, @@ -450,6 +446,12 @@ "Dict keys are `'lat'` and `'lon'`", "Sets the center point of the map.", ], + mapbox_style=[ + "str (default `'basic'`, needs Mapbox API token)", + "Identifier of base map style, some of which require a Mapbox API token to be set using `plotly.express.set_mapbox_access_token()`.", + "Allowed values which do not require a Mapbox API token are `'open-street-map'`, `'white-bg'`, `'carto-positron'`, `'carto-darkmatter'`, `'stamen-terrain'`, `'stamen-toner'`, `'stamen-watercolor'`.", + "Allowed values which do require a Mapbox API token are `'basic'`, `'streets'`, `'outdoors'`, `'light'`, `'dark'`, `'satellite'`, `'satellite-streets'`.", + ], points=[ "str or boolean (default `'outliers'`)", "One of `'outliers'`, `'suspectedoutliers'`, `'all'`, or `False`.", From 4a9b4b6de3169c3e4b072755e7cb96c31f7aac58 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 30 Nov 2019 22:29:01 -0500 Subject: [PATCH 4/8] fixing ids in election dataset --- .../package_data/datasets/election.csv.gz | Bin 1581 -> 1568 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/packages/python/plotly/plotly/package_data/datasets/election.csv.gz b/packages/python/plotly/plotly/package_data/datasets/election.csv.gz index 710a53a53518c94fd81861f0f93095908ac71745..9038c29a41e1fa8ab1d4c36685b2bd8f85f9fdb7 100644 GIT binary patch literal 1568 zcmV+*2H*J~iwFpAGUHtU17&PwV{~b6ZZ2bUb^v`>%TgOh6y4`5Tx_zLcJ=$Q4Dzce zuqkk5-@} zwHJ->GBk=y-8iN6_e{6#RAQUQhdEZVMZ9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X9+3TJpz@vEw1aPA`wu)8?5Ypn?1V2NAkU~pT&ACG<9_=_~eJO`I z6!9*$Ih|d_Az>ir-I&+ix{YT~RN4Q|{5Ir?D_9WLER6&6t*gAmmy;@I4kcbe?9O&y zHWOZj1~f$N1toHot$msGmeaGFy9Q~_7C-*?$3M-UbT?fbb3aL@rHq6-Pq3-Wl4->g zbi4;V_OgoeqmUgl@aZf@4X6Asl@E#<_aZeH>NFr)clo+o7 zn!IGMKM%3(6aBwXD41I>F?B?0!;9>~v3MebARZVX1BcBJt4orM!!Qw$Ylo&t27njH zvMI_C?!Y{@1N|H~40?~;TsTuHV`SkK$oDI-D7EW>TH+-5pem*zz$qoldIRA;$W_nY z$F!b6Wawmj=shPUYAU$|1&H=d+ug6GcQu5b>l%;4qo81S8hp^{_Z>P!(VIyq-{#$) z)7`h0JdTEB3vkaGcUl6ZW{d8jYXW9eE0n2lA%(%~P-=ZL1iHK$U(7>GwhdlNLq};o z036;r?Wdr{7cX(xHZeco9(UVrS|#vTQH>nafxW4VKvj~x>GFVk)-+))snVOKA))q9*1P*h_loUDxSutnC@ zMGQi~uM+*7>W{XC^Y81Su+BE-~d)+mEkt(=kPp=#r430BZ99V2$>$I+5nPDfc>=*rE+mP zE?^DsZh@~beoSPJH0bZ}XNJb%=iZd(i=%PfeT<+Z8IjQUn6gr&QW_4+@0n2yR)@b( fz{~CK5uq5A0TmQb!VOuK)1m(Z#szgzQ4RnAsHykN From 2ed2b11629de7f866bcafe9defeca56d44e80898 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sun, 1 Dec 2019 21:31:25 -0500 Subject: [PATCH 5/8] geopandas helper --- packages/python/plotly/plotly/express/_chart_types.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index 4ac3cc3956..d2f7d64649 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1029,7 +1029,11 @@ def choropleth_mapbox( return make_figure( args=locals(), constructor=go.Choroplethmapbox, - trace_patch=dict(geojson=geojson), + trace_patch=dict( + geojson=geojson + if not hasattr(geojson, "__geo_interface__") + else geojson.__geo_interface__ + ), ) From 5eb7740196191280daeb45fa84444014fd5cac2d Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 2 Dec 2019 13:46:02 -0500 Subject: [PATCH 6/8] fix tests and add new ones --- .../plotly/plotly/express/_chart_types.py | 2 + test/percy/plotly-express.py | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index d2f7d64649..7644a63819 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1094,6 +1094,8 @@ def line_mapbox( color_discrete_sequence=None, color_discrete_map={}, zoom=8, + center=None, + mapbox_style=None, title=None, template=None, width=None, diff --git a/test/percy/plotly-express.py b/test/percy/plotly-express.py index 0342f33394..a39167bb8b 100644 --- a/test/percy/plotly-express.py +++ b/test/percy/plotly-express.py @@ -435,6 +435,45 @@ import plotly.express as px +sample_geojson = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "id": "the_polygon", + "geometry": { + "type": "Polygon", + "coordinates": [ + [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]] + ], + }, + } + ], +} +fig = px.choropleth_mapbox( + geojson=sample_geojson, + locations=["the_polygon"], + color=[10], + mapbox_style="carto-positron", + zoom=6, +) +fig.write_html(os.path.join(dir_name, "choropleth_mapbox.html"), auto_play=False) + +import plotly.express as px + +carshare = px.data.carshare() +fig = px.density_mapbox( + carshare, + lat="centroid_lat", + lon="centroid_lon", + z="peak_hour", + mapbox_style="carto-positron", +) +fig.write_html(os.path.join(dir_name, "density_mapbox.html"), auto_play=False) + +import plotly.express as px + + gapminder = px.data.gapminder() fig = px.scatter_geo( gapminder, From 014ce9ebbd8d684c998653184b895f9e4a18aadf Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 2 Dec 2019 14:45:08 -0500 Subject: [PATCH 7/8] more percy tests --- test/percy/plotly-express.py | 51 +++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/test/percy/plotly-express.py b/test/percy/plotly-express.py index a39167bb8b..53c577baf8 100644 --- a/test/percy/plotly-express.py +++ b/test/percy/plotly-express.py @@ -451,11 +451,7 @@ ], } fig = px.choropleth_mapbox( - geojson=sample_geojson, - locations=["the_polygon"], - color=[10], - mapbox_style="carto-positron", - zoom=6, + geojson=sample_geojson, locations=["the_polygon"], color=[10], zoom=6, ) fig.write_html(os.path.join(dir_name, "choropleth_mapbox.html"), auto_play=False) @@ -463,11 +459,7 @@ carshare = px.data.carshare() fig = px.density_mapbox( - carshare, - lat="centroid_lat", - lon="centroid_lon", - z="peak_hour", - mapbox_style="carto-positron", + carshare, lat="centroid_lat", lon="centroid_lon", z="peak_hour", ) fig.write_html(os.path.join(dir_name, "density_mapbox.html"), auto_play=False) @@ -509,3 +501,42 @@ range_color=[20, 80], ) fig.write_html(os.path.join(dir_name, "choropleth.html"), auto_play=False) + +import plotly.express as px + +tips = px.data.tips() +fig = px.pie(tips, names="smoker", values="total_bill") +fig.write_html(os.path.join(dir_name, "pie.html"), auto_play=False) + +import plotly.express as px + +tips = px.data.tips() +fig = px.funnel_area(tips, names="smoker", values="total_bill") +fig.write_html(os.path.join(dir_name, "funnel_area.html"), auto_play=False) + +import plotly.express as px + +fig = px.treemap( + names=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"], + parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"], + values=[10, 14, 12, 10, 2, 6, 6, 4, 4], +) +fig.write_html(os.path.join(dir_name, "treemap.html"), auto_play=False) + + +import plotly.express as px + +fig = px.sunburst( + names=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"], + parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"], + values=[10, 14, 12, 10, 2, 6, 6, 4, 4], +) +fig.write_html(os.path.join(dir_name, "sunburst.html"), auto_play=False) + + +import plotly.express as px + +fig = px.funnel( + y=["first", "second", "first", "second"], x=[3,1,4,2], color=["A", "A", "B", "B"] +) +fig.write_html(os.path.join(dir_name, "funnel.html"), auto_play=False) From 8ce78bef27138586cc7f48d269eaacc565e2566b Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 2 Dec 2019 15:05:02 -0500 Subject: [PATCH 8/8] black --- test/percy/plotly-express.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/percy/plotly-express.py b/test/percy/plotly-express.py index 53c577baf8..854e2d2369 100644 --- a/test/percy/plotly-express.py +++ b/test/percy/plotly-express.py @@ -537,6 +537,6 @@ import plotly.express as px fig = px.funnel( - y=["first", "second", "first", "second"], x=[3,1,4,2], color=["A", "A", "B", "B"] + y=["first", "second", "first", "second"], x=[3, 1, 4, 2], color=["A", "A", "B", "B"] ) fig.write_html(os.path.join(dir_name, "funnel.html"), auto_play=False)