From dccbdf887cc7c1d5e5f89369457ee4b974a95299 Mon Sep 17 00:00:00 2001 From: Rob L Date: Wed, 13 Mar 2024 23:06:10 -0400 Subject: [PATCH 01/16] proposed addition of a df.agg stacked go.bar example --- doc/python/bar-charts.md | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 9e9b30755b..6c0b66b6fd 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -304,6 +304,57 @@ fig.update_layout(barmode='stack') fig.show() ``` +### Stacked Bar Chart from aggregating a data frame + +Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands, which produce a wide format data set with one row for each bar component and a column for each bar, which is the transpose of the orientation of the px.bar wide data frame. Tranposing and updating the indexes is a somewhat involved option. Here is one straightforward way to aggregate a data set into a summarized form and present the results as a stacked bar. + +``` + +from plotly import graph_objects as go +import pandas as pd + +#get one year of gapminder data +url = 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv' +df = pd.read_csv(url) +df = df[df['year']==2007] +df["gdp"]=df["pop"]*df['gdpPercap'] + + +#build the summary of interest +df_summarized = df.groupby("continent", observed=True).agg("sum").reset_index() + +df_summarized["percent of world population"]=100*df_summarized["pop"]/df_summarized["pop"].sum() +df_summarized["percent of world GDP"]=100*df_summarized["gdp"]/df_summarized["gdp"].sum() + + +df2 = df_summarized[["continent", +"percent of world population", +"percent of world GDP", +]] + +#we now have a wide data frame, but it's in the opposite orientation from the one that px is designed to deal with. +#transposing it and rebuilding the indexes is an option, but iterating through the DF using graph objects is more succinct. + +fig=go.Figure() +for category in df_summarized["continent"].values: + fig.add_trace(go.Bar( + x=df2.columns[1:], + #we need to get a pandas series that contains just the values to graph; + #we do so by selecting the right row, selecting the right columns + #and then tranposing and using iloc to convert to a series + #here, I assume that the bar element category variable is in column 0 + y=list(df2.loc[df2["continent"]==category][list(df2.columns[1:])].transpose().iloc[:,0]), + name=str(category) + + + ) +) +fig.update_layout(barmode="stack") + +fig.show() +``` + + ### Bar Chart with Hover Text ```python From b8a198da1be086df62ea9988d512f0ed1f220850 Mon Sep 17 00:00:00 2001 From: Rob L Date: Wed, 13 Mar 2024 23:17:49 -0400 Subject: [PATCH 02/16] Update bar-charts.md renamed df2 to df --- doc/python/bar-charts.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 6c0b66b6fd..a2ef93572d 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -327,7 +327,7 @@ df_summarized["percent of world population"]=100*df_summarized["pop"]/df_summari df_summarized["percent of world GDP"]=100*df_summarized["gdp"]/df_summarized["gdp"].sum() -df2 = df_summarized[["continent", +df = df_summarized[["continent", "percent of world population", "percent of world GDP", ]] @@ -338,12 +338,12 @@ df2 = df_summarized[["continent", fig=go.Figure() for category in df_summarized["continent"].values: fig.add_trace(go.Bar( - x=df2.columns[1:], + x=df.columns[1:], #we need to get a pandas series that contains just the values to graph; #we do so by selecting the right row, selecting the right columns #and then tranposing and using iloc to convert to a series #here, I assume that the bar element category variable is in column 0 - y=list(df2.loc[df2["continent"]==category][list(df2.columns[1:])].transpose().iloc[:,0]), + y=list(df.loc[df["continent"]==category][list(df.columns[1:])].transpose().iloc[:,0]), name=str(category) From 32a2c0cc2950eab38b78b606b08849bedc6adf62 Mon Sep 17 00:00:00 2001 From: Rob L Date: Wed, 13 Mar 2024 23:19:25 -0400 Subject: [PATCH 03/16] Update bar-charts.md --- doc/python/bar-charts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index a2ef93572d..90672e7117 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -306,7 +306,7 @@ fig.show() ### Stacked Bar Chart from aggregating a data frame -Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands, which produce a wide format data set with one row for each bar component and a column for each bar, which is the transpose of the orientation of the px.bar wide data frame. Tranposing and updating the indexes is a somewhat involved option. Here is one straightforward way to aggregate a data set into a summarized form and present the results as a stacked bar. +Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands. DF.agg() which produces a wide format data set with one row for each bar component and a column for each bar, which is the transpose of the orientation of the px.bar wide data frame. Tranposing and updating the indexes is a somewhat involved option. Here is one straightforward way to aggregate a data set into a summarized form and present the results as a stacked bar. ``` From 5e8942781ad757d33f0c5204ab169f93edc25f50 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:32:03 -0400 Subject: [PATCH 04/16] Update doc/python/bar-charts.md Co-authored-by: Liam Connors --- doc/python/bar-charts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 90672e7117..af12665a01 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -304,7 +304,7 @@ fig.update_layout(barmode='stack') fig.show() ``` -### Stacked Bar Chart from aggregating a data frame +### Stacked Bar Chart From Aggregating a DataFrame Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands. DF.agg() which produces a wide format data set with one row for each bar component and a column for each bar, which is the transpose of the orientation of the px.bar wide data frame. Tranposing and updating the indexes is a somewhat involved option. Here is one straightforward way to aggregate a data set into a summarized form and present the results as a stacked bar. From d628817425f5abf5d1a05bb13cb2d1067571d181 Mon Sep 17 00:00:00 2001 From: Rob L Date: Mon, 25 Mar 2024 14:01:05 -0700 Subject: [PATCH 05/16] Update hover-text-and-formatting.md 1) added an example that formats the elements of custom_data in plotly express 2) fixed a bug in the "advanced hovertemplate" example which caused it to display the square root of population. Modified that example to follow the main dataframe is called "df" convention. Added a country name field to that example and comments about the usage of key parameters. 3) I did not remove the "Adding other data to the hover with customdata and a hovertemplate" example, but I believe it is now redundant and that the revised ### Advanced Hover Template example is more compliant with expectations like using meaningful data over random data. If you removed it, it would make sense to rename "Advanced Hover Template" to include the phrase: "Adding other data to the hover with customdata and a hovertemplate" --- doc/python/hover-text-and-formatting.md | 93 ++++++++++++++++++++----- 1 file changed, 77 insertions(+), 16 deletions(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index 2d4ae985c1..d5cf8f8ca9 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -252,6 +252,58 @@ print("user_defined hovertemplate:", fig.data[0].hovertemplate) fig.show() ``` +### Specifying the formatting and labeling of custom fields in a Plotly Express figure using a hovertemplate + +This example adds custom fields to a Plotly Express figure using the custom_data parameter and then adds a hover template that applies d3 formats to each element of the customdata[n] array and uses HTML to customize the fonts and spacing. + +``` +# %% +import plotly.graph_objects as go +import plotly.express as px +import pandas as pd +import math +import numpy as np + +data = px.data.gapminder() +df = data[data['year']==2007] +df = df.sort_values(['continent', 'country']) + +df.rename(columns={"gdpPercap":'GDP per capita', "lifeExp":'Life Expectancy (years)'}, inplace=True) + +fig=px.scatter(df, + x='GDP per capita', + y='Life Expectancy (years)', + color='continent', + size=np.sqrt(df['pop']), + # Specifying data to make availabe to the hovertemplate + # The px custom_data parameter has an underscore, whike the analogous graph objects customdata parameter has no underscore. + # The px custom_data parameter is a list of column names in the data frame, while the graph objects customdata parameter expects a data frame or a numpy array. + custom_data=['country', 'continent', 'pop'], +) + +# Plotly express does not have a hovertemplate paramter in the graph creation function, so we apply the template with update_traces +fig.update_traces( + hovertemplate = + "%{customdata[0]}
" + + "%{customdata[1]}

" + + "GDP per Capita: %{x:$,.0f}
" + + "Life Expectation: %{y:.0f}
" + + "Population: %{customdata[2]:,.0f}" + + "", + mode='markers', + marker={'sizemode':'area', + 'sizeref':10}, +) + +fig.update_layout( + xaxis={ + 'type':'log'}, + ) + +fig.show() +``` + + ### Hover Templates with Mixtures of Period data *New in v5.0* @@ -288,9 +340,8 @@ fig.show() ### Advanced Hover Template -The following example shows how to format a hover template. - -```python +This produces the same graphic as in "Specifying the formatting and labeling of custom fields in a Plotly Express figure using a hovertemplate" above, but does so with the `customdata` and `text` parameters of `graph_objects`. It shows how to specify columns from a dataframe to include in the customdata array using the df[["col_i", "col_j"]] subsetting notation. It then references those variables using e.g. %{customdata[0]} in the hovertemplate. It includes comments about major differences between the parameters used by `graph_objects` and `plotly.express`. +``` import plotly.graph_objects as go import plotly.express as px import pandas as pd @@ -312,21 +363,31 @@ continent_data = {continent:df_2007.query("continent == '%s'" %continent) fig = go.Figure() -for continent_name, continent in continent_data.items(): - fig.add_trace(go.Scatter( - x=continent['gdpPercap'], - y=continent['lifeExp'], - name=continent_name, - text=continent['continent'], - hovertemplate= - "%{text}

" + - "GDP per Capita: %{x:$,.0f}
" + - "Life Expectation: %{y:.0%}
" + - "Population: %{marker.size:,}" + - "", - marker_size=continent['size'], +for continent_name, df in continent_data.items(): + fig.add_trace( + go.Scatter( + x=df['gdpPercap'], + y=df['lifeExp'], + marker_size=df['size'], + name=continent_name, + + # The next three parameters specify the hover text + # Text supports just one customized field per trace, but is simple to implement + text=df['continent'], + # Custom data supports multiple fields through numeric indices in the hovertemplate + # If I were not looking for an opportunity to demonstrate the text parameter, + # I would likely just add continent as a third customdata field. + customdata=df[['country','pop']], + hovertemplate= + "%{customdata[0]}
" + + "%{text}

" + + "GDP per Capita: %{x:$,.0f}
" + + "Life Expectancy: %{y:.0f}
" + + "Population: %{customdata[1]:,.0f}" + + "", )) + fig.update_traces( mode='markers', marker={'sizemode':'area', From eca3711d6dc0fe3bd5b4712137a9623c8e9d9637 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Wed, 10 Apr 2024 09:33:53 -0400 Subject: [PATCH 06/16] Update doc/python/bar-charts.md --- doc/python/bar-charts.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index af12665a01..213bc9f9bc 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -313,14 +313,14 @@ Stacked bar charts are a powerful way to present results summarizing categories from plotly import graph_objects as go import pandas as pd -#get one year of gapminder data +# Get one year of gapminder data url = 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv' df = pd.read_csv(url) df = df[df['year']==2007] df["gdp"]=df["pop"]*df['gdpPercap'] -#build the summary of interest +# Build the summary of interest df_summarized = df.groupby("continent", observed=True).agg("sum").reset_index() df_summarized["percent of world population"]=100*df_summarized["pop"]/df_summarized["pop"].sum() @@ -332,17 +332,17 @@ df = df_summarized[["continent", "percent of world GDP", ]] -#we now have a wide data frame, but it's in the opposite orientation from the one that px is designed to deal with. -#transposing it and rebuilding the indexes is an option, but iterating through the DF using graph objects is more succinct. +# We now have a wide data frame, but it's in the opposite orientation from the one that px is designed to deal with. +# Transposing it and rebuilding the indexes is an option, but iterating through the DF using graph objects is more succinct. fig=go.Figure() for category in df_summarized["continent"].values: fig.add_trace(go.Bar( x=df.columns[1:], - #we need to get a pandas series that contains just the values to graph; - #we do so by selecting the right row, selecting the right columns - #and then tranposing and using iloc to convert to a series - #here, I assume that the bar element category variable is in column 0 + # We need to get a pandas series that contains just the values to graph; + # We do so by selecting the right row, selecting the right columns + # and then transposing and using iloc to convert to a series + # Here, we assume that the bar element category variable is in column 0 y=list(df.loc[df["continent"]==category][list(df.columns[1:])].transpose().iloc[:,0]), name=str(category) From c3fbb647d6f4fe6ef5047927a6f54e4c2c525bd1 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Wed, 10 Apr 2024 09:34:07 -0400 Subject: [PATCH 07/16] Update doc/python/bar-charts.md --- doc/python/bar-charts.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 213bc9f9bc..635a348d24 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -306,8 +306,7 @@ fig.show() ### Stacked Bar Chart From Aggregating a DataFrame -Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands. DF.agg() which produces a wide format data set with one row for each bar component and a column for each bar, which is the transpose of the orientation of the px.bar wide data frame. Tranposing and updating the indexes is a somewhat involved option. Here is one straightforward way to aggregate a data set into a summarized form and present the results as a stacked bar. - +Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands. `pandas.DataFrame.agg` produces a wide data set format incompatible with `px.bar`. Transposing and updating the indexes to achieve `px.bar` compatibility is a somewhat involved option. Here is one straightforward alternative, which presents the aggregated data as a stacked bar using plotly.graph_objects. ``` from plotly import graph_objects as go From b786d9cf6a7eeb7428d67ba596beacc815e1659c Mon Sep 17 00:00:00 2001 From: Shiv Munagala <104731185+ShivMunagala@users.noreply.github.com> Date: Thu, 18 Apr 2024 22:03:40 +0100 Subject: [PATCH 08/16] fix: Code block not rendering Code block under the subtitle 'Stacked Bar Chart From Aggregating a DataFrame' wasn't rendering because language declaration for the block was missing. --- doc/python/bar-charts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 635a348d24..7134ab2c68 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -307,8 +307,8 @@ fig.show() ### Stacked Bar Chart From Aggregating a DataFrame Stacked bar charts are a powerful way to present results summarizing categories generated using the Pandas aggregate commands. `pandas.DataFrame.agg` produces a wide data set format incompatible with `px.bar`. Transposing and updating the indexes to achieve `px.bar` compatibility is a somewhat involved option. Here is one straightforward alternative, which presents the aggregated data as a stacked bar using plotly.graph_objects. -``` +```python from plotly import graph_objects as go import pandas as pd From 1e63ed46a39e5cc865a3a0573bada777b50e9f06 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 22 Apr 2024 11:36:57 -0400 Subject: [PATCH 09/16] Update doc/python/hover-text-and-formatting.md Co-authored-by: Adam --- doc/python/hover-text-and-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index d5cf8f8ca9..7cae455a63 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -275,7 +275,7 @@ fig=px.scatter(df, y='Life Expectancy (years)', color='continent', size=np.sqrt(df['pop']), - # Specifying data to make availabe to the hovertemplate + # Specifying data to make available to the hovertemplate # The px custom_data parameter has an underscore, whike the analogous graph objects customdata parameter has no underscore. # The px custom_data parameter is a list of column names in the data frame, while the graph objects customdata parameter expects a data frame or a numpy array. custom_data=['country', 'continent', 'pop'], From 70655ea7515640630dc12a7b75b16a4318c56629 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 22 Apr 2024 11:37:19 -0400 Subject: [PATCH 10/16] Update doc/python/hover-text-and-formatting.md --- doc/python/hover-text-and-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index 7cae455a63..b4bc755c14 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -254,7 +254,7 @@ fig.show() ### Specifying the formatting and labeling of custom fields in a Plotly Express figure using a hovertemplate -This example adds custom fields to a Plotly Express figure using the custom_data parameter and then adds a hover template that applies d3 formats to each element of the customdata[n] array and uses HTML to customize the fonts and spacing. +This example adds custom fields to a Plotly Express figure using the custom_data parameter and then adds a hover template that applies d3 formats to each element of the customdata[n] array and uses HTML to customize the fonts and spacing. ``` # %% From 02cf1b105ef6b7ada26b6c6c1f870f21a9af5dc1 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 22 Apr 2024 11:37:29 -0400 Subject: [PATCH 11/16] Update doc/python/hover-text-and-formatting.md Co-authored-by: Adam --- doc/python/hover-text-and-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index b4bc755c14..4394774c86 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -276,7 +276,7 @@ fig=px.scatter(df, color='continent', size=np.sqrt(df['pop']), # Specifying data to make available to the hovertemplate - # The px custom_data parameter has an underscore, whike the analogous graph objects customdata parameter has no underscore. + # The px custom_data parameter has an underscore, while the analogous graph objects customdata parameter has no underscore. # The px custom_data parameter is a list of column names in the data frame, while the graph objects customdata parameter expects a data frame or a numpy array. custom_data=['country', 'continent', 'pop'], ) From 7c4b95474a5c96f015665623e05a6ecb5c35d30a Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 22 Apr 2024 11:37:42 -0400 Subject: [PATCH 12/16] Update doc/python/hover-text-and-formatting.md Co-authored-by: Adam --- doc/python/hover-text-and-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index 4394774c86..74ec119a1f 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -281,7 +281,7 @@ fig=px.scatter(df, custom_data=['country', 'continent', 'pop'], ) -# Plotly express does not have a hovertemplate paramter in the graph creation function, so we apply the template with update_traces +# Plotly express does not have a hovertemplate parameter in the graph creation function, so we apply the template with update_traces fig.update_traces( hovertemplate = "%{customdata[0]}
" + From fb060bda825d638291c690645002ed0d911cb9cb Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 22 Apr 2024 12:31:51 -0400 Subject: [PATCH 13/16] Update doc/python/hover-text-and-formatting.md --- doc/python/hover-text-and-formatting.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index 74ec119a1f..79e673bb56 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -372,8 +372,8 @@ for continent_name, df in continent_data.items(): name=continent_name, # The next three parameters specify the hover text - # Text supports just one customized field per trace, but is simple to implement - text=df['continent'], + # Text supports just one customized field per trace + # and is implemented here with text=df['continent'], # Custom data supports multiple fields through numeric indices in the hovertemplate # If I were not looking for an opportunity to demonstrate the text parameter, # I would likely just add continent as a third customdata field. From b06b80b31e5ad9db4d4ed19d0e449b4286253bf6 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 22 Apr 2024 12:32:02 -0400 Subject: [PATCH 14/16] Update doc/python/hover-text-and-formatting.md --- doc/python/hover-text-and-formatting.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index 79e673bb56..a8da71a3a9 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -375,8 +375,8 @@ for continent_name, df in continent_data.items(): # Text supports just one customized field per trace # and is implemented here with text=df['continent'], # Custom data supports multiple fields through numeric indices in the hovertemplate - # If I were not looking for an opportunity to demonstrate the text parameter, - # I would likely just add continent as a third customdata field. + # In we weren't using the text parameter in our example, + # we could instead add continent as a third customdata field. customdata=df[['country','pop']], hovertemplate= "%{customdata[0]}
" + From eba6910ea7f6069e977f1f02b83d701b08da7ad2 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Tue, 23 Apr 2024 16:16:45 -0400 Subject: [PATCH 15/16] Update doc/python/hover-text-and-formatting.md --- doc/python/hover-text-and-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index d97545222c..a6fa39bacd 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -287,7 +287,7 @@ fig.show() This example adds custom fields to a Plotly Express figure using the custom_data parameter and then adds a hover template that applies d3 formats to each element of the customdata[n] array and uses HTML to customize the fonts and spacing. -``` +```python # %% import plotly.graph_objects as go import plotly.express as px From 217ed661dbdbd97107083ede081b251f09f76e4a Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Wed, 24 Apr 2024 09:51:59 -0400 Subject: [PATCH 16/16] Update doc/python/hover-text-and-formatting.md --- doc/python/hover-text-and-formatting.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/python/hover-text-and-formatting.md b/doc/python/hover-text-and-formatting.md index a6fa39bacd..50befc860f 100644 --- a/doc/python/hover-text-and-formatting.md +++ b/doc/python/hover-text-and-formatting.md @@ -372,7 +372,8 @@ fig.show() ### Advanced Hover Template This produces the same graphic as in "Specifying the formatting and labeling of custom fields in a Plotly Express figure using a hovertemplate" above, but does so with the `customdata` and `text` parameters of `graph_objects`. It shows how to specify columns from a dataframe to include in the customdata array using the df[["col_i", "col_j"]] subsetting notation. It then references those variables using e.g. %{customdata[0]} in the hovertemplate. It includes comments about major differences between the parameters used by `graph_objects` and `plotly.express`. -``` + +```python import plotly.graph_objects as go import plotly.express as px import pandas as pd