From ddb0f78ffca1f116142f4ed78fd211e4cdfbb6db Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 10 Oct 2024 15:10:42 -0400 Subject: [PATCH 1/4] remove deprecated attributes --- doc/python/3d-bubble-charts.md | 74 ++++++++++++++++++---- doc/python/bar-charts.md | 20 +++--- doc/python/carpet-contour.md | 5 +- doc/python/colorscales.md | 12 ++-- doc/python/contour-plots.md | 15 +++-- doc/python/multiple-axes.md | 32 ++++++---- doc/python/network-graphs.md | 14 ++-- doc/python/range-slider.md | 36 ++++++++--- doc/python/scatter-plots-on-maps.md | 4 +- doc/python/setting-graph-size.md | 24 +++++-- doc/python/ternary-plots.md | 3 +- doc/unconverted/python/cars-exploration.md | 8 +-- 12 files changed, 178 insertions(+), 69 deletions(-) diff --git a/doc/python/3d-bubble-charts.md b/doc/python/3d-bubble-charts.md index 0877a6b55e4..3020f27d21c 100644 --- a/doc/python/3d-bubble-charts.md +++ b/doc/python/3d-bubble-charts.md @@ -113,12 +113,36 @@ fig = go.Figure(data=go.Scatter3d( ) )) -fig.update_layout(width=800, height=800, title = 'Planets!', - scene = dict(xaxis=dict(title='Distance from Sun', titlefont_color='white'), - yaxis=dict(title='Density', titlefont_color='white'), - zaxis=dict(title='Gravity', titlefont_color='white'), - bgcolor = 'rgb(20, 24, 54)' - )) +fig.update_layout( + width=800, + height=800, + title="Planets!", + scene=dict( + xaxis=dict( + title=dict( + text="Distance from Sun", + font=dict( + color="white" + ) + ), + yaxis=dict( + title=dict( + text="Density", + font=dict( + color="white" + ) + ), + zaxis=dict( + title=dict( + text="Gravity", + font=dict( + color="white" + ) + ), + bgcolor="rgb(20, 24, 54)", + ), +) + fig.show() ``` @@ -154,12 +178,38 @@ fig = go.Figure(go.Scatter3d( ) )) -fig.update_layout(width=800, height=800, title = 'Planets!', - scene = dict(xaxis=dict(title='Distance from Sun', titlefont_color='white'), - yaxis=dict(title='Density', titlefont_color='white'), - zaxis=dict(title='Gravity', titlefont_color='white'), - bgcolor = 'rgb(20, 24, 54)' - )) +fig.update_layout( + width=800, + height=800, + title="Planets!", + scene=dict( + xaxis=dict( + title=dict( + text="Distance from Sun", + font=dict( + color="white" + ) + ) + ), + yaxis=dict( + title=dict( + text="Density", + font=dict( + color="white" + ) + ) + ), + zaxis=dict( + title=dict( + text="Gravity", + font=dict( + color="white" + ) + ) + ), + bgcolor="rgb(20, 24, 54)" + ) +) fig.show() ``` diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 7134ab2c68f..e93439cf1f9 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -37,7 +37,7 @@ jupyter: [Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/). -With `px.bar`, **each row of the DataFrame is represented as a rectangular mark**. To aggregate multiple data points into the same rectangular mark, please refer to the [histogram documentation](/python/histograms). +With `px.bar`, **each row of the DataFrame is represented as a rectangular mark**. To aggregate multiple data points into the same rectangular mark, please refer to the [histogram documentation](/python/histograms). In the example below, there is only a single row of data per year, so a single bar is displayed per year. @@ -152,7 +152,7 @@ fig.show() ### Aggregating into Single Colored Bars -As noted above `px.bar()` will result in **one rectangle drawn per row of input**. This can sometimes result in a striped look as in the examples above. To combine these rectangles into one per color per position, you can use `px.histogram()`, which has [its own detailed documentation page](/python/histogram). +As noted above `px.bar()` will result in **one rectangle drawn per row of input**. This can sometimes result in a striped look as in the examples above. To combine these rectangles into one per color per position, you can use `px.histogram()`, which has [its own detailed documentation page](/python/histogram). > `px.bar` and `px.histogram` are designed to be nearly interchangeable in their call signatures, so as to be able to switch between aggregated and disaggregated bar representations. @@ -304,7 +304,7 @@ fig.update_layout(barmode='stack') fig.show() ``` -### Stacked Bar Chart From Aggregating a DataFrame +### 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. @@ -326,19 +326,19 @@ 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() -df = df_summarized[["continent", +df = 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. +# 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 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 @@ -619,8 +619,12 @@ fig.update_layout( title='US Export of Plastic Scrap', xaxis_tickfont_size=14, yaxis=dict( - title='USD (millions)', - titlefont_size=16, + title=dict( + text="USD (millions)", + font=dict( + size=16 + ) + ), tickfont_size=14, ), legend=dict( diff --git a/doc/python/carpet-contour.md b/doc/python/carpet-contour.md index 0d11800ea18..87642243977 100644 --- a/doc/python/carpet-contour.md +++ b/doc/python/carpet-contour.md @@ -159,9 +159,10 @@ fig.add_trace(go.Contourcarpet( colorbar = dict( y = 0, yanchor = "bottom", - titleside = "right", len = 0.75, - title = "Pressure coefficient, cp" + title = dict( + text="Pressure coefficient, cp", + side="right") ), contours = dict( start = -1, diff --git a/doc/python/colorscales.md b/doc/python/colorscales.md index 7e2aeb9ad73..757ff54911e 100644 --- a/doc/python/colorscales.md +++ b/doc/python/colorscales.md @@ -321,8 +321,10 @@ fig = go.Figure() fig.add_trace(go.Heatmap( z=dataset["z"], colorbar=dict( - title="Surface Heat", - titleside="top", + title=dict( + text="Surface Heat", + side="top", + ), tickmode="array", tickvals=[2, 25, 50, 75, 100], labelalias={100: "Hot", 50: "Mild", 2: "Cold"}, @@ -545,8 +547,10 @@ fig = go.Figure() fig.add_trace(go.Heatmap( z=dataset["z"], colorbar=dict( - title="Surface Heat", - titleside="top", + title=dict( + text="Surface Heat", + side="top", + ), tickmode="array", tickvals=[2, 50, 100], ticktext=["Cool", "Mild", "Hot"], diff --git a/doc/python/contour-plots.md b/doc/python/contour-plots.md index feb4f3b68a2..4ba74b175d4 100644 --- a/doc/python/contour-plots.md +++ b/doc/python/contour-plots.md @@ -281,12 +281,15 @@ fig = go.Figure(data= [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorbar=dict( - title='Color bar title', # title here - titleside='right', - titlefont=dict( - size=14, - family='Arial, sans-serif') - ))) + title=dict( + text='Color bar title', # title here + side='right', + font=dict( + size=14, + family='Arial, sans-serif') + ) + ), + )) fig.show() ``` diff --git a/doc/python/multiple-axes.md b/doc/python/multiple-axes.md index 5bbdeda3c93..5a8deae7e53 100644 --- a/doc/python/multiple-axes.md +++ b/doc/python/multiple-axes.md @@ -192,18 +192,22 @@ fig.update_layout( domain=[0.3, 0.7] ), yaxis=dict( - title="yaxis title", - titlefont=dict( - color="#1f77b4" + title=dict( + text="yaxis title", + font=dict( + color="#1f77b4" + ) ), tickfont=dict( color="#1f77b4" ) ), yaxis2=dict( - title="yaxis2 title", - titlefont=dict( - color="#ff7f0e" + title=dict( + text="yaxis2 title", + font=dict( + color="#ff7f0e" + ) ), tickfont=dict( color="#ff7f0e" @@ -214,9 +218,11 @@ fig.update_layout( position=0.15 ), yaxis3=dict( - title="yaxis3 title", - titlefont=dict( - color="#d62728" + title=dict( + text="yaxis3 title", + font=dict( + color="#d62728" + ) ), tickfont=dict( color="#d62728" @@ -226,9 +232,11 @@ fig.update_layout( side="right" ), yaxis4=dict( - title="yaxis4 title", - titlefont=dict( - color="#9467bd" + title=dict( + text="yaxis4 title", + font=dict( + color="#9467bd" + ) ), tickfont=dict( color="#9467bd" diff --git a/doc/python/network-graphs.md b/doc/python/network-graphs.md index 9d2f3fec2e2..ae47e9923c0 100644 --- a/doc/python/network-graphs.md +++ b/doc/python/network-graphs.md @@ -98,9 +98,11 @@ node_trace = go.Scatter( size=10, colorbar=dict( thickness=15, - title='Node Connections', + title=dict( + text='Node Connections', + side='right' + ), xanchor='left', - titleside='right' ), line_width=2)) @@ -128,8 +130,12 @@ node_trace.text = node_text ```python fig = go.Figure(data=[edge_trace, node_trace], layout=go.Layout( - title='
Network graph made with Python', - titlefont_size=16, + title=dict( + text="
Network graph made with Python", + font=dict( + size=16 + ) + ), showlegend=False, hovermode='closest', margin=dict(b=20,l=5,r=5,t=40), diff --git a/doc/python/range-slider.md b/doc/python/range-slider.md index 9d1bce3bde6..bd6744fe7ac 100644 --- a/doc/python/range-slider.md +++ b/doc/python/range-slider.md @@ -252,7 +252,11 @@ fig.update_layout( tickfont={"color": "#673ab7"}, tickmode="auto", ticks="", - titlefont={"color": "#673ab7"}, + title=dict( + font=dict( + color="#673ab7" + ) + ), type="linear", zeroline=False ), @@ -268,7 +272,11 @@ fig.update_layout( tickfont={"color": "#E91E63"}, tickmode="auto", ticks="", - titlefont={"color": "#E91E63"}, + title=dict( + font=dict( + color="#E91E63" + ) + ), type="linear", zeroline=False ), @@ -284,8 +292,12 @@ fig.update_layout( tickfont={"color": "#795548"}, tickmode="auto", ticks="", - title="mg/L", - titlefont={"color": "#795548"}, + title=dict( + text="mg/L", + font=dict( + color="#795548" + ) + ), type="linear", zeroline=False ), @@ -301,8 +313,12 @@ fig.update_layout( tickfont={"color": "#607d8b"}, tickmode="auto", ticks="", - title="mmol/L", - titlefont={"color": "#607d8b"}, + title=dict( + text="mmol/L", + font=dict( + color="#607d8b" + ) + ), type="linear", zeroline=False ), @@ -318,8 +334,12 @@ fig.update_layout( tickfont={"color": "#2196F3"}, tickmode="auto", ticks="", - title="mg/Kg", - titlefont={"color": "#2196F3"}, + title=dict( + text="mg/Kg", + font=dict( + color="#2196F3" + ) + ), type="linear", zeroline=False ) diff --git a/doc/python/scatter-plots-on-maps.md b/doc/python/scatter-plots-on-maps.md index 9c4ad70bea8..e22a019eb6e 100644 --- a/doc/python/scatter-plots-on-maps.md +++ b/doc/python/scatter-plots-on-maps.md @@ -187,7 +187,9 @@ fig = go.Figure(data=go.Scattergeo( opacity = 0.7, size = 2, colorbar = dict( - titleside = "right", + title = dict( + side="right" + ), outlinecolor = "rgba(68, 68, 68, 0)", ticks = "outside", showticksuffix = "last", diff --git a/doc/python/setting-graph-size.md b/doc/python/setting-graph-size.md index 611e0e29825..717c25341df 100644 --- a/doc/python/setting-graph-size.md +++ b/doc/python/setting-graph-size.md @@ -118,11 +118,15 @@ fig.update_layout( width=500, height=500, yaxis=dict( - title_text="Y-axis Title", + title=dict( + text="Y-axis Title", + font=dict( + size=30 + ) + ), ticktext=["Very long label", "long label", "3", "label"], tickvals=[1, 2, 3, 4], tickmode="array", - titlefont=dict(size=30), ) ) @@ -153,11 +157,15 @@ fig.update_layout( width=500, height=500, yaxis=dict( - title_text="Y-axis Title", + title=dict( + text="Y-axis Title", + font=dict( + size=30 + ) + ), ticktext=["Very long label", "long label", "3", "label"], tickvals=[1, 2, 3, 4], tickmode="array", - titlefont=dict(size=30), ) ) @@ -190,11 +198,15 @@ fig.update_layout( width=450, height=450, yaxis=dict( - title_text="Y-axis Title", + title=dict( + text="Y-axis Title", + font=dict( + size=30 + ) + ), ticktext=["Label", "Very long label", "Other label", "Very very long label"], tickvals=[1, 2, 3, 4], tickmode="array", - titlefont=dict(size=30), ) ) diff --git a/doc/python/ternary-plots.md b/doc/python/ternary-plots.md index a389faba417..84e3de7cf67 100644 --- a/doc/python/ternary-plots.md +++ b/doc/python/ternary-plots.md @@ -82,8 +82,7 @@ rawData = [ def makeAxis(title, tickangle): return { - 'title': title, - 'titlefont': { 'size': 20 }, + 'title': {'text': title, 'font': { 'size': 20}, 'tickangle': tickangle, 'tickfont': { 'size': 15 }, 'tickcolor': 'rgba(0,0,0,0)', diff --git a/doc/unconverted/python/cars-exploration.md b/doc/unconverted/python/cars-exploration.md index 34bb4aad123..70344867e54 100644 --- a/doc/unconverted/python/cars-exploration.md +++ b/doc/unconverted/python/cars-exploration.md @@ -109,19 +109,19 @@ fig.layout.title = 'Torque and Fuel Efficience' Check default font size ```python -fig.layout.titlefont.size +fig.layout.title.font.size ``` Increase the title font size ```python -fig.layout.titlefont.size = 22 +fig.layout.title.font.size = 22 ``` -Set `fig.layout.titlefont.family` to `'Rockwell'` +Set `fig.layout.title.font.family` to `'Rockwell'` ```python -fig.layout.titlefont.family = 'Rockwell' +fig.layout.title.font.family = 'Rockwell' ``` ### Create New View for Figure From 0094d5ad7c6e8ee127ca7bf4a8755997c245811c Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 10 Oct 2024 15:27:02 -0400 Subject: [PATCH 2/4] fix syntax error --- doc/python/3d-bubble-charts.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/python/3d-bubble-charts.md b/doc/python/3d-bubble-charts.md index 3020f27d21c..f4ab9dc44ab 100644 --- a/doc/python/3d-bubble-charts.md +++ b/doc/python/3d-bubble-charts.md @@ -5,10 +5,10 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.2.3 + format_version: '1.3' + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 + display_name: Python 3 (ipykernel) language: python name: python3 language_info: @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.7.3 + version: 3.11.10 plotly: description: How to make 3D Bubble Charts in Python with Plotly. Three examples of 3D Bubble Charts. @@ -124,6 +124,7 @@ fig.update_layout( font=dict( color="white" ) + ) ), yaxis=dict( title=dict( @@ -216,4 +217,4 @@ fig.show() #### Reference -See https://plotly.com/python/reference/scatter3d/ and https://plotly.com/python/reference/scatter/#scatter-marker-sizeref
for more information and chart attribute options! \ No newline at end of file +See https://plotly.com/python/reference/scatter3d/ and https://plotly.com/python/reference/scatter/#scatter-marker-sizeref
for more information and chart attribute options! From 482e8f8923a1925f7942245291ea99dd2b5049b8 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 10 Oct 2024 15:28:25 -0400 Subject: [PATCH 3/4] fix syntax error --- doc/python/ternary-plots.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/python/ternary-plots.md b/doc/python/ternary-plots.md index 84e3de7cf67..f53a0862b08 100644 --- a/doc/python/ternary-plots.md +++ b/doc/python/ternary-plots.md @@ -5,10 +5,10 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.3' + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 + display_name: Python 3 (ipykernel) language: python name: python3 language_info: @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.11.10 plotly: description: How to make Ternary plots in Python with Plotly. display_as: scientific @@ -82,7 +82,7 @@ rawData = [ def makeAxis(title, tickangle): return { - 'title': {'text': title, 'font': { 'size': 20}, + 'title': {'text': title, 'font': { 'size': 20}}, 'tickangle': tickangle, 'tickfont': { 'size': 15 }, 'tickcolor': 'rgba(0,0,0,0)', From 827d9dc2680f4382d8f1b4fe0f58c69e1f63e79b Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 10 Oct 2024 15:52:38 -0400 Subject: [PATCH 4/4] fix example --- doc/python/3d-bubble-charts.md | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/doc/python/3d-bubble-charts.md b/doc/python/3d-bubble-charts.md index f4ab9dc44ab..8abaf0fbdcc 100644 --- a/doc/python/3d-bubble-charts.md +++ b/doc/python/3d-bubble-charts.md @@ -119,29 +119,31 @@ fig.update_layout( title="Planets!", scene=dict( xaxis=dict( - title=dict( - text="Distance from Sun", - font=dict( - color="white" - ) - ) + title=dict( + text="Distance from Sun", + font=dict( + color="white" + ) + ) ), yaxis=dict( - title=dict( - text="Density", - font=dict( - color="white" + title=dict( + text="Density", + font=dict( + color="white" + ) ) ), zaxis=dict( - title=dict( - text="Gravity", - font=dict( - color="white" + title=dict( + text="Gravity", + font=dict( + color="white" + ) ) - ), - bgcolor="rgb(20, 24, 54)", - ), + ), + bgcolor="rgb(20, 24, 54)" + ) )