From 69134eb18f570773bf124da377813fdb0a7f74d5 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 21 Nov 2022 12:01:12 -0500 Subject: [PATCH 1/3] Update dumbbell-plots.md --- doc/python/dumbbell-plots.md | 93 +++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 33 deletions(-) diff --git a/doc/python/dumbbell-plots.md b/doc/python/dumbbell-plots.md index 224187c659..6217ab7ede 100644 --- a/doc/python/dumbbell-plots.md +++ b/doc/python/dumbbell-plots.md @@ -55,39 +55,51 @@ countries = ( .unique() ) -data = {"x": [], "y": [], "colors": [], "years": []} +data = {"line_x": [], "line_y": [], "1952": [], "2002": [], "colors": [], "years": [], "countries": []} for country in countries: - data["x"].extend( + data["1952"].extend([df.loc[(df.year == 1952) & (df.country == country)]["lifeExp"].values[0]]) + data["2002"].extend([df.loc[(df.year == 2002) & (df.country == country)]["lifeExp"].values[0]]) + data["line_x"].extend( [ df.loc[(df.year == 1952) & (df.country == country)]["lifeExp"].values[0], df.loc[(df.year == 2002) & (df.country == country)]["lifeExp"].values[0], None, ] ) - data["y"].extend([country, country, None]), - data["colors"].extend(["green", "blue", "brown"]), - data["years"].extend(["1952", "2002", None]) + data["line_y"].extend([country, country, None]), fig = go.Figure( data=[ go.Scatter( - x=data["x"], - y=data["y"], + x=data["line_x"], + y=data["line_y"], mode="lines", + showlegend=False, marker=dict( - color="grey", - ), + color='grey' + ) ), go.Scatter( - x=data["x"], - y=data["y"], - mode="markers+text", + x=data["1952"], + y=countries, + mode="markers", + name="1952", marker=dict( - color=data["colors"], - size=10, - ), - hovertemplate="""Country: %{y}
Life Expectancy: %{x}
""", + color="green", + size=10 + ) + + ), + go.Scatter( + x=data["2002"], + y=countries, + mode="markers", + name="2002", + marker=dict( + color="blue", + size=10 + ) ), ] ) @@ -95,7 +107,7 @@ fig = go.Figure( fig.update_layout( title="Life Expectancy in Europe: 1952 and 2002", height=1000, - showlegend=False, + legend_itemclick=False ) fig.show() @@ -123,41 +135,56 @@ countries = ( .sort_values(by=["lifeExp"], ascending=True)["country"] .unique() ) - -data = {"x": [], "y": [], "colors": [], "years": []} + +data = {"line_x": [], "line_y": [], "1952": [], "2002": [], "colors": [], "years": [], "countries": []} for country in countries: - data["x"].extend( + data["1952"].extend([df.loc[(df.year == 1952) & (df.country == country)]["lifeExp"].values[0]]) + data["2002"].extend([df.loc[(df.year == 2002) & (df.country == country)]["lifeExp"].values[0]]) + data["line_x"].extend( [ df.loc[(df.year == 1952) & (df.country == country)]["lifeExp"].values[0], df.loc[(df.year == 2002) & (df.country == country)]["lifeExp"].values[0], None, ] ) - data["y"].extend([country, country, None]), - data["colors"].extend(["silver", "lightskyblue", "white"]), - data["years"].extend(["1952", "2002", None]) + data["line_y"].extend([country, country, None]), + fig = go.Figure( data=[ go.Scatter( - x=data["x"], - y=data["y"], + x=data["line_x"], + y=data["line_y"], mode="markers+lines", + showlegend=False, marker=dict( - symbol="arrow", color="black", size=16, angleref="previous", standoff=8 - ), + symbol="arrow", + color="black", + size=16, + angleref="previous", + standoff=8 + ) + ), + go.Scatter( + x=data["1952"], + y=countries, + name="1952", + mode="markers", + marker=dict( + color="silver", + size=16, + ) ), go.Scatter( - x=data["x"], - y=data["y"], - text=data["years"], + x=data["2002"], + y=countries, + name="2002", mode="markers", marker=dict( - color=data["colors"], + color="lightskyblue", size=16, ), - hovertemplate="""Country: %{y}
Life Expectancy: %{x}
Year: %{text}
""", ), ] ) @@ -165,7 +192,7 @@ fig = go.Figure( fig.update_layout( title="Life Expectancy in Europe: 1952 and 2002", height=1000, - showlegend=False, + legend_itemclick=False ) From 8cb48154ba55c0ade1b74aeb6376533c8d7b4e4a Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Tue, 22 Nov 2022 10:05:48 -0500 Subject: [PATCH 2/3] Update dumbbell-plots.md --- doc/python/dumbbell-plots.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/dumbbell-plots.md b/doc/python/dumbbell-plots.md index 6217ab7ede..8061b80474 100644 --- a/doc/python/dumbbell-plots.md +++ b/doc/python/dumbbell-plots.md @@ -77,7 +77,7 @@ fig = go.Figure( mode="lines", showlegend=False, marker=dict( - color='grey' + color="grey" ) ), go.Scatter( From 1da06f9befd1cc2cfb135f23f956fa3a41e79c77 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Tue, 22 Nov 2022 10:11:33 -0500 Subject: [PATCH 3/3] Update dumbbell-plots.md --- doc/python/dumbbell-plots.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/python/dumbbell-plots.md b/doc/python/dumbbell-plots.md index 8061b80474..fa93915eee 100644 --- a/doc/python/dumbbell-plots.md +++ b/doc/python/dumbbell-plots.md @@ -135,7 +135,7 @@ countries = ( .sort_values(by=["lifeExp"], ascending=True)["country"] .unique() ) - + data = {"line_x": [], "line_y": [], "1952": [], "2002": [], "colors": [], "years": [], "countries": []} for country in countries: @@ -150,7 +150,6 @@ for country in countries: ) data["line_y"].extend([country, country, None]), - fig = go.Figure( data=[ go.Scatter(