diff --git a/doc/python/3d-axes.md b/doc/python/3d-axes.md index a64bf9f29b8..b6ec1d8d3e0 100644 --- a/doc/python/3d-axes.md +++ b/doc/python/3d-axes.md @@ -159,9 +159,22 @@ fig.add_trace(go.Mesh3d(x=(70*np.random.randn(N)), )) fig.update_layout(scene = dict( - xaxis_title='X AXIS TITLE', - yaxis_title='Y AXIS TITLE', - zaxis_title='Z AXIS TITLE'), + xaxis=dict( + title=dict( + text='X AXIS TITLE' + ) + ), + yaxis=dict( + title=dict( + text='Y AXIS TITLE' + ) + ), + zaxis=dict( + title=dict( + text='Z AXIS TITLE' + ) + ), + ), width=700, margin=dict(r=20, b=10, l=10, t=10)) diff --git a/doc/python/3d-bubble-charts.md b/doc/python/3d-bubble-charts.md index f4b57248d8b..db6de7bf01b 100644 --- a/doc/python/3d-bubble-charts.md +++ b/doc/python/3d-bubble-charts.md @@ -77,7 +77,7 @@ fig = go.Figure(data=go.Scatter3d( fig.update_layout(height=800, width=800, - title='Examining Population and Life Expectancy Over Time') + title=dict(text='Examining Population and Life Expectancy Over Time')) fig.show() ``` @@ -116,7 +116,7 @@ fig = go.Figure(data=go.Scatter3d( fig.update_layout( width=800, height=800, - title="Planets!", + title=dict(text="Planets!"), scene=dict( xaxis=dict( title=dict( @@ -183,7 +183,7 @@ fig = go.Figure(go.Scatter3d( fig.update_layout( width=800, height=800, - title="Planets!", + title=dict(text="Planets!"), scene=dict( xaxis=dict( title=dict( diff --git a/doc/python/3d-camera-controls.md b/doc/python/3d-camera-controls.md index 5ec5879bb26..749e72f21ee 100644 --- a/doc/python/3d-camera-controls.md +++ b/doc/python/3d-camera-controls.md @@ -53,7 +53,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=40, r=0, l=20, b=20) ) @@ -85,7 +85,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -112,7 +112,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -138,7 +138,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -163,7 +163,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -189,7 +189,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -216,7 +216,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -243,7 +243,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=30, r=0, l=20, b=10) ) @@ -273,7 +273,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=go.Surface(z=z_data, showscale=False)) fig.update_layout( - title='Mt Bruno Elevation', + title=dict(text='Mt Bruno Elevation'), width=400, height=400, margin=dict(t=25, r=0, l=20, b=30) ) diff --git a/doc/python/3d-mesh.md b/doc/python/3d-mesh.md index fec2097972e..610c8153a90 100644 --- a/doc/python/3d-mesh.md +++ b/doc/python/3d-mesh.md @@ -97,7 +97,7 @@ fig = go.Figure(data=[ x=[0, 1, 2, 0], y=[0, 0, 1, 2], z=[0, 2, 0, 1], - colorbar_title='z', + colorbar=dict(title=dict(text='z')), colorscale=[[0, 'gold'], [0.5, 'mediumturquoise'], [1, 'magenta']], @@ -128,7 +128,7 @@ fig = go.Figure(data=[ x=[0, 0, 1, 1, 0, 0, 1, 1], y=[0, 1, 1, 0, 0, 1, 1, 0], z=[0, 0, 0, 0, 1, 1, 1, 1], - colorbar_title='z', + colorbar=dict(title=dict(text='z')), colorscale=[[0, 'gold'], [0.5, 'mediumturquoise'], [1, 'magenta']], @@ -160,7 +160,7 @@ fig = go.Figure(data=[ x=[0, 0, 1, 1, 0, 0, 1, 1], y=[0, 1, 1, 0, 0, 1, 1, 0], z=[0, 0, 0, 0, 1, 1, 1, 1], - colorbar_title='z', + colorbar=dict(title=dict(text='z')), colorscale=[[0, 'gold'], [0.5, 'mediumturquoise'], [1, 'magenta']], diff --git a/doc/python/3d-surface-plots.md b/doc/python/3d-surface-plots.md index a7b561e7a6c..8b042d3fcb9 100644 --- a/doc/python/3d-surface-plots.md +++ b/doc/python/3d-surface-plots.md @@ -46,7 +46,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=[go.Surface(z=z_data.values)]) -fig.update_layout(title='Mt Bruno Elevation', autosize=False, +fig.update_layout(title=dict(text='Mt Bruno Elevation'), autosize=False, width=500, height=500, margin=dict(l=65, r=50, b=65, t=90)) @@ -67,7 +67,7 @@ z = z_data.values sh_0, sh_1 = z.shape x, y = np.linspace(0, 1, sh_0), np.linspace(0, 1, sh_1) fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)]) -fig.update_layout(title='Mt Bruno Elevation', autosize=False, +fig.update_layout(title=dict(text='Mt Bruno Elevation'), autosize=False, width=500, height=500, margin=dict(l=65, r=50, b=65, t=90)) fig.show() @@ -90,7 +90,7 @@ z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/a fig = go.Figure(data=[go.Surface(z=z_data.values)]) fig.update_traces(contours_z=dict(show=True, usecolormap=True, highlightcolor="limegreen", project_z=True)) -fig.update_layout(title='Mt Bruno Elevation', autosize=False, +fig.update_layout(title=dict(text='Mt Bruno Elevation'), autosize=False, scene_camera_eye=dict(x=1.87, y=0.88, z=-0.64), width=500, height=500, margin=dict(l=65, r=50, b=65, t=90) diff --git a/doc/python/animations.md b/doc/python/animations.md index 045111c90e7..c61162693e3 100644 --- a/doc/python/animations.md +++ b/doc/python/animations.md @@ -30,6 +30,7 @@ jupyter: order: 1 page_type: example_index permalink: python/animations/ + redirect_from: python/visualizing-mri-volume-slices/ thumbnail: thumbnail/animations.gif --- @@ -125,7 +126,7 @@ fig = go.Figure( layout=go.Layout( xaxis=dict(range=[0, 5], autorange=False), yaxis=dict(range=[0, 5], autorange=False), - title="Start Title", + title=dict(text="Start Title"), updatemenus=[dict( type="buttons", buttons=[dict(label="Play", @@ -171,7 +172,7 @@ fig = go.Figure( fig.update_layout(width=600, height=450, xaxis=dict(range=[xm, xM], autorange=False, zeroline=False), yaxis=dict(range=[ym, yM], autorange=False, zeroline=False), - title_text="Kinematic Generation of a Planar Curve", title_x=0.5, + title_text="Kinematic Generation of a Planar Curve", title_x=0.5, updatemenus = [dict(type = "buttons", buttons = [ dict( @@ -179,9 +180,9 @@ fig.update_layout(width=600, height=450, "fromcurrent": True, "transition": {"duration": 10}}], label = "Play", method = "animate", - + )])]) - + fig.update(frames=[go.Frame( data=[go.Scatter( x=[xx[k]], @@ -239,7 +240,7 @@ fig = go.Figure( layout=go.Layout(width=600, height=600, xaxis=dict(range=[xm, xM], autorange=False, zeroline=False), yaxis=dict(range=[ym, yM], autorange=False, zeroline=False), - title="Moving Frenet Frame Along a Planar Curve", + title=dict(text="Moving Frenet Frame Along a Planar Curve"), hovermode="closest", updatemenus=[dict(type="buttons", buttons=[dict(label="Play", diff --git a/doc/python/axes.md b/doc/python/axes.md index 851fb142db8..df8672e0e2e 100644 --- a/doc/python/axes.md +++ b/doc/python/axes.md @@ -649,8 +649,8 @@ import plotly.express as px df = px.data.stocks(indexed=True) fig = px.line(df, df.index, y="GOOG") -fig.update_yaxes(ticklabelposition="inside", title="Price") -fig.update_xaxes(insiderange=['2018-10-01', '2019-01-01'], title="Date") +fig.update_yaxes(ticklabelposition="inside", title=dict(text="Price")) +fig.update_xaxes(insiderange=['2018-10-01', '2019-01-01'], title=dict(text="Date")) fig.show() ``` diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index 9ee75ea4406..f16955a93b7 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -693,7 +693,7 @@ fig.add_trace(go.Bar(x=years, )) fig.update_layout( - title='US Export of Plastic Scrap', + title=dict(text='US Export of Plastic Scrap'), xaxis_tickfont_size=14, yaxis=dict( title=dict( diff --git a/doc/python/box-plots.md b/doc/python/box-plots.md index 5ca79d51b0f..244c21106ef 100644 --- a/doc/python/box-plots.md +++ b/doc/python/box-plots.md @@ -367,7 +367,10 @@ fig.add_trace(go.Box( )) fig.update_layout( - yaxis_title='normalized moisture', + yaxis=dict( + title=dict( + text='normalized moisture') + ), boxmode='group' # group together boxes of the different traces for each value of x ) fig.show() @@ -402,7 +405,7 @@ fig.add_trace(go.Box( )) fig.update_layout( - xaxis=dict(title='normalized moisture', zeroline=False), + xaxis=dict(title=dict(text='normalized moisture'), zeroline=False), boxmode='group' ) @@ -479,7 +482,7 @@ for xd, yd, cls in zip(x_data, y_data, colors): ) fig.update_layout( - title='Points Scored by the Top 9 Scoring NBA Players in 2012', + title=dict(text='Points Scored by the Top 9 Scoring NBA Players in 2012'), yaxis=dict( autorange=True, showgrid=True, diff --git a/doc/python/bubble-charts.md b/doc/python/bubble-charts.md index b5bc5ad966d..ad574b2a1ef 100644 --- a/doc/python/bubble-charts.md +++ b/doc/python/bubble-charts.md @@ -202,15 +202,15 @@ fig.update_traces(mode='markers', marker=dict(sizemode='area', sizeref=sizeref, line_width=2)) fig.update_layout( - title='Life Expectancy v. Per Capita GDP, 2007', + title=dict(text='Life Expectancy v. Per Capita GDP, 2007'), xaxis=dict( - title='GDP per capita (2000 dollars)', + title=dict(text='GDP per capita (2000 dollars)'), gridcolor='white', type='log', gridwidth=2, ), yaxis=dict( - title='Life Expectancy (years)', + title=dict(text='Life Expectancy (years)'), gridcolor='white', gridwidth=2, ), diff --git a/doc/python/candlestick-charts.md b/doc/python/candlestick-charts.md index d4b98cc1979..06273b4ad43 100644 --- a/doc/python/candlestick-charts.md +++ b/doc/python/candlestick-charts.md @@ -106,8 +106,12 @@ fig = go.Figure(data=[go.Candlestick(x=df['Date'], ]) fig.update_layout( - title='The Great Recession', - yaxis_title='AAPL Stock', + title=dict(text='The Great Recession'), + yaxis=dict( + title=dict( + text='AAPL Stock' + ) + ), shapes = [dict( x0='2016-12-09', x1='2016-12-09', y0=0, y1=1, xref='x', yref='paper', line_width=2)], diff --git a/doc/python/choropleth-maps.md b/doc/python/choropleth-maps.md index 6cdf73d51e0..e38e51befde 100644 --- a/doc/python/choropleth-maps.md +++ b/doc/python/choropleth-maps.md @@ -287,7 +287,11 @@ fig = go.Figure(data=go.Choropleth( autocolorscale=False, text=df['text'], # hover text marker_line_color='white', # line markers between states - colorbar_title="Millions USD" + colorbar=dict( + title=dict( + text="Millions USD" + ) + ) )) fig.update_layout( diff --git a/doc/python/colorscales.md b/doc/python/colorscales.md index 757ff54911e..61e84314d4d 100644 --- a/doc/python/colorscales.md +++ b/doc/python/colorscales.md @@ -246,7 +246,7 @@ df = px.data.tips() fig = px.density_heatmap(df, x="total_bill", y="tip", title="Customized color bar on this density plot") fig.update_layout(coloraxis_colorbar=dict( - title="Number of Bills per Cell", + title=dict(text="Number of Bills per Cell"), thicknessmode="pixels", thickness=50, lenmode="pixels", len=200, yanchor="top", y=1, @@ -271,7 +271,7 @@ fig = px.parallel_coordinates(df, dimensions=["sepal_length", "sepal_width", "pe (0.66, "blue"), (1.00, "blue")]) fig.update_layout(coloraxis_colorbar=dict( - title="Species", + title=dict(text="Species"), tickvals=[1,2,3], ticktext=["setosa","versicolor","virginica"], lenmode="pixels", len=100, @@ -291,7 +291,7 @@ df = px.data.gapminder().query("year == 2007") fig = px.scatter(df, y="lifeExp", x="pop", color=np.log10(df["pop"]), hover_name="country", log_x=True) fig.update_layout(coloraxis_colorbar=dict( - title="Population", + title=dict(text="Population"), tickvals=[6,7,8,9], ticktext=["1M", "10M", "100M", "1B"], )) @@ -408,7 +408,7 @@ fig.add_trace(go.Scatter( cmin=0, color=values, colorbar=dict( - title="Colorbar" + title=dict(text="Colorbar") ), colorscale="Viridis" ), @@ -659,7 +659,7 @@ fig = go.Figure(go.Heatmap( colorbar=dict( x=0.2, xref="container", - title="Surface Heat" + title=dict(text="Surface Heat") ) )) diff --git a/doc/python/continuous-error-bars.md b/doc/python/continuous-error-bars.md index 9706c0c6ab7..529033bb63d 100644 --- a/doc/python/continuous-error-bars.md +++ b/doc/python/continuous-error-bars.md @@ -108,8 +108,8 @@ fig = go.Figure([ ) ]) fig.update_layout( - yaxis_title='Wind speed (m/s)', - title='Continuous, variable value error bars', + yaxis=dict(title=dict(text='Wind speed (m/s)')), + title=dict(text='Continuous, variable value error bars'), hovermode="x" ) fig.show() diff --git a/doc/python/contour-plots.md b/doc/python/contour-plots.md index 4ba74b175d4..897564ce391 100644 --- a/doc/python/contour-plots.md +++ b/doc/python/contour-plots.md @@ -153,8 +153,8 @@ fig.add_trace(go.Contour(z=z, showscale=False, connectgaps=True), 1, 2) fig.add_trace(go.Heatmap(z=z, showscale=False, zsmooth='best'), 2, 1) fig.add_trace(go.Heatmap(z=z, showscale=False, connectgaps=True, zsmooth='best'), 2, 2) -fig['layout']['yaxis1'].update(title='Contour map') -fig['layout']['yaxis3'].update(title='Heatmap') +fig['layout']['yaxis1'].update(title=dict(text='Contour map')) +fig['layout']['yaxis3'].update(title=dict(text='Heatmap')) fig.show() ``` diff --git a/doc/python/county-choropleth.md b/doc/python/county-choropleth.md index 935f3f649e0..1e4410db37f 100644 --- a/doc/python/county-choropleth.md +++ b/doc/python/county-choropleth.md @@ -120,7 +120,14 @@ fig = ff.create_choropleth( fips=fips, values=values, scope=['CA', 'AZ', 'Nevada', 'Oregon', ' Idaho'], binning_endpoints=[14348, 63983, 134827, 426762, 2081313], colorscale=colorscale, county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, round_legend_values=True, - legend_title='Population by County', title='California and Nearby States' + legend=dict( + title=dict( + text='Population by County' + ) + ), + title=dict( + text='California and Nearby States' + ) ) fig.layout.template = None fig.show() diff --git a/doc/python/dot-plots.md b/doc/python/dot-plots.md index ed9d7b6c239..5d42411865d 100644 --- a/doc/python/dot-plots.md +++ b/doc/python/dot-plots.md @@ -98,9 +98,21 @@ fig.add_trace(go.Scatter( name="Men", )) -fig.update_layout(title="Gender Earnings Disparity", - xaxis_title="Annual Salary (in thousands)", - yaxis_title="School") +fig.update_layout( + title=dict( + text="Gender Earnings Disparity" + ), + xaxis=dict( + title=dict( + text="Annual Salary (in thousands)" + ) + ), + yaxis=dict( + title=dict( + text="School" + ) + ), +) fig.show() ``` @@ -139,7 +151,7 @@ fig.add_trace(go.Scatter( fig.update_traces(mode='markers', marker=dict(line_width=1, symbol='circle', size=16)) fig.update_layout( - title="Votes cast for ten lowest voting age population in OECD countries", + title=dict(text="Votes cast for ten lowest voting age population in OECD countries"), xaxis=dict( showgrid=False, showline=True, diff --git a/doc/python/dropdowns.md b/doc/python/dropdowns.md index 3944f1a2689..222b794e804 100644 --- a/doc/python/dropdowns.md +++ b/doc/python/dropdowns.md @@ -444,5 +444,104 @@ fig.update_layout(title_text="Yahoo") fig.show() ``` +### Graph Selection Dropdowns in Jinja + +It is straight forward to create each potential view as a separate graph and then use Jinja to insert each potential view into a div on a JavaScript enabled webpage with a dropdown that chooses which div to display. This approach produces code that requires little customization or updating as you e.g. add, drop, or reorder views or traces, so it is particularly compelling for prototyping and rapid iteration. It produces web pages that are larger than the webpages produced through the built in method which is a consideration for very large figures with hundreds or thousands of data points in traces that appear in multiple selections. This approach requires both a Python program and a Jinja template file. The documentation on [using Jinja templates with Plotly](https://plotly.com/python/interactive-html-export/#inserting-plotly-output-into-html-using-a-jinja2-template) is relevant background. + + + +#### Python Code File + +```python +import plotly.express as px +from jinja2 import Template +import collections +# Load the gapminder dataset +df = px.data.gapminder() + +# Create a dictionary with Plotly figures as values +fig_dict = {} + +# we need to fill that dictionary with figures. this example assumes that each figure has a title and that +# we want to use the titles as descriptions in the drop down +# This example happens to fill the dictionary by creating a scatter plot for each continent using the 2007 Gapminder data +for continent in df['continent'].unique(): + # Filter data for the current continent + continent_data = df[(df['continent'] == continent) & (df['year'] == 2007)] + + fig_dict[continent] = px.scatter(continent_data, x='gdpPercap', y='lifeExp', + title=f'GDP vs Life Expectancy for {continent}', + labels={'gdpPercap': 'GDP per Capita (USD)', 'lifeExp': 'Life Expectancy (Years)'}, + hover_name='country',size="pop", size_max=55 + ) + #Standardizing the axes makes the graphs easier to compare + fig_dict[continent].update_xaxes(range=[0,50000]) + fig_dict[continent].update_yaxes(range=[25,90]) + + +# Create a dictionary, data_for_jinja with two entries: +# the value for the "dropdown_entries" key is a string containing a series of