diff --git a/doc/python/.mapbox_token b/doc/python/.mapbox_token new file mode 100644 index 00000000000..7dc5cd2dd8c --- /dev/null +++ b/doc/python/.mapbox_token @@ -0,0 +1 @@ +pk.eyJ1IjoiZXRwaW5hcmQiLCJhIjoiY2luMHIzdHE0MGFxNXVubTRxczZ2YmUxaCJ9.hwWZful0U2CQxit4ItNsiQ diff --git a/doc/python/animations.md b/doc/python/animations.md index bf8e21dd230..85f933395a1 100644 --- a/doc/python/animations.md +++ b/doc/python/animations.md @@ -5,12 +5,22 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.6 + format_version: '1.1' + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python name: python3 + language_info: + codemirror_mode: + name: ipython + version: 3 + file_extension: .py + mimetype: text/x-python + name: python + nbconvert_exporter: python + pygments_lexer: ipython3 + version: 3.7.3 plotly: description: An introduction to creating animations with Plotly in Python. display_as: animations @@ -31,6 +41,7 @@ Here is an example of an animated scatter plot creating using Plotly Express. No ```python import plotly.express as px + df = px.data.gapminder() px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country", size="pop", color="continent", hover_name="country", @@ -45,10 +56,9 @@ Note that you should always fix the `y_range` to ensure that your data remains v import plotly.express as px df = px.data.gapminder() - fig = px.bar(df, x="continent", y="pop", color="continent", animation_frame="year", animation_group="country", range_y=[0,4000000000]) -fig.show() +fig.show() ``` #### Animated figures with Graph Objects diff --git a/doc/python/bubble-maps.md b/doc/python/bubble-maps.md index 6563221d923..0d40ab95df0 100644 --- a/doc/python/bubble-maps.md +++ b/doc/python/bubble-maps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.1' + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make bubble maps in Python with Plotly. display_as: maps @@ -78,7 +78,6 @@ See https://plot.ly/python/reference/#scatter-marker-sizeref for more informatio ```python import plotly.graph_objects as go - import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv') @@ -96,27 +95,22 @@ for i in range(len(limits)): lim = limits[i] df_sub = df[lim[0]:lim[1]] fig.add_trace(go.Scattergeo( - locationmode = 'USA-states', - lon = df_sub['lon'], - lat = df_sub['lat'], - text = df_sub['text'], - marker = dict( - size = df_sub['pop']/scale, - color = colors[i], + locationmode='USA-states', + lon=df_sub['lon'], + lat=df_sub['lat'], + text=df_sub['text'], + marker=dict( + size=df_sub['pop']/scale, + color=colors[i], line_color='rgb(40,40,40)', line_width=0.5, - sizemode = 'area' - ), - name = '{0} - {1}'.format(lim[0],lim[1]))) + sizemode='area'), + name='{0} - {1}'.format(lim[0],lim[1]))) fig.update_layout( - title_text = '2014 US city populations
(Click legend to toggle traces)', - showlegend = True, - geo = dict( - scope = 'usa', - landcolor = 'rgb(217, 217, 217)', - ) - ) + title_text='2014 US city populations
(Click legend to toggle traces)', + showlegend=True, + geo=dict(scope='usa', landcolor='rgb(217, 217, 217)')) fig.show() ``` @@ -125,7 +119,6 @@ fig.show() ```python import plotly.graph_objects as go - import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_ebola.csv') @@ -146,8 +139,7 @@ for i in range(6,10)[::-1]: marker = dict( size = df_month['Value']/50, color = colors[i-6], - line_width = 0 - ))) + line_width = 0))) df_sept = df.query('Month == 9') fig['data'][0].update(mode='markers+text', textposition='bottom center', @@ -156,52 +148,42 @@ fig['data'][0].update(mode='markers+text', textposition='bottom center', # Inset fig.add_trace(go.Choropleth( - locationmode = 'country names', - locations = df_sept['Country'], - z = df_sept['Value'], - text = df_sept['Country'], - colorscale = [[0,'rgb(0, 0, 0)'],[1,'rgb(0, 0, 0)']], - autocolorscale = False, - showscale = False, - geo = 'geo2' - )) -fig.add_trace(go.Scattergeo( - lon = [21.0936], - lat = [7.1881], - text = ['Africa'], - mode = 'text', - showlegend = False, - geo = 'geo2' - )) - + locationmode='country names', + locations=df_sept['Country'], + z=df_sept['Value'], + text=df_sept['Country'], + colorscale=[[0,'rgb(0, 0, 0)'],[1,'rgb(0, 0, 0)']], + autocolorscale=False, + showscale=False, + geo='geo2')) + +fig.add_trace(go.Scattergeo(lon=[21.0936], lat=[7.1881], text=['Africa'], mode='text', + showlegend=False, geo='geo2')) fig.update_layout( - title = go.layout.Title( - text = 'Ebola cases reported by month in West Africa 2014
\ + title = dict( + text='Ebola cases reported by month in West Africa 2014
\ Source: \ HDX'), - geo = go.layout.Geo( - resolution = 50, - scope = 'africa', - showframe = False, - showcoastlines = True, - landcolor = "rgb(229, 229, 229)", - countrycolor = "white" , - coastlinecolor = "white", - projection_type = 'mercator', - lonaxis_range= [ -15.0, -5.0 ], - lataxis_range= [ 0.0, 12.0 ], - domain = dict(x = [ 0, 1 ], y = [ 0, 1 ]) - ), - geo2 = go.layout.Geo( - scope = 'africa', - showframe = False, - landcolor = "rgb(229, 229, 229)", - showcountries = False, - domain = dict(x = [ 0, 0.6 ], y = [ 0, 0.6 ]), - bgcolor = 'rgba(255, 255, 255, 0.0)', - ), - legend_traceorder = 'reversed' -) + geo = dict( + resolution=50, + scope='africa', + showframe=False, + showcoastlines=True, + landcolor="rgb(229, 229, 229)", + countrycolor="white" , + coastlinecolor="white", + projection_type='mercator', + lonaxis_range=[ -15.0, -5.0 ], + lataxis_range=[ 0.0, 12.0 ], + domain = dict(x=[ 0, 1 ], y=[ 0, 1 ])), + geo2 = dict( + scope='africa', + showframe=False, + landcolor="rgb(229, 229, 229)", + showcountries=False, + domain=dict(x=[ 0, 0.6 ], y=[ 0, 0.6 ]), + bgcolor='rgba(255, 255, 255, 0.0)'), + legend_traceorder='reversed') fig.show() ``` diff --git a/doc/python/choropleth-maps.md b/doc/python/choropleth-maps.md index ca2b1383f58..bddb941d31b 100644 --- a/doc/python/choropleth-maps.md +++ b/doc/python/choropleth-maps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.2" - jupytext_version: 1.3.1 + format_version: '1.1' + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.8 + version: 3.7.3 plotly: description: How to make choropleth maps in Python with Plotly. display_as: maps @@ -207,9 +207,9 @@ fig.show() ```python import plotly.graph_objects as go +import pandas as pd # Load data frame and tidy it. -import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv') fig = go.Figure(data=go.Choropleth( @@ -217,13 +217,11 @@ fig = go.Figure(data=go.Choropleth( z = df['total exports'].astype(float), # Data to be color-coded locationmode = 'USA-states', # set of locations match entries in `locations` colorscale = 'Reds', - colorbar_title = "Millions USD", -)) + colorbar_title = "Millions USD")) fig.update_layout( title_text = '2011 US Agriculture Exports by State', - geo_scope='usa', # limite map scope to USA -) + geo_scope='usa') # limite map scope to USA fig.show() ``` @@ -232,8 +230,8 @@ fig.show() ```python import plotly.graph_objects as go - import pandas as pd + df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv') for col in df.columns: @@ -252,17 +250,13 @@ 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_title="Millions USD")) fig.update_layout( title_text='2011 US Agriculture Exports by State
(Hover for breakdown)', - geo = dict( - scope='usa', - projection=go.layout.geo.Projection(type = 'albers usa'), - showlakes=True, # lakes - lakecolor='rgb(255, 255, 255)'), -) + geo=dict(scope='usa', projection=dict(type = 'albers usa'), + showlakes=True, # lakes + lakecolor='rgb(255, 255, 255)')) fig.show() ``` @@ -285,16 +279,14 @@ fig = go.Figure(data=go.Choropleth( marker_line_color='darkgray', marker_line_width=0.5, colorbar_tickprefix = '$', - colorbar_title = 'GDP
Billions US$', -)) + colorbar_title = 'GDP
Billions US$')) fig.update_layout( title_text='2014 Global GDP', geo=dict( showframe=False, showcoastlines=False, - projection_type='equirectangular' - ), + projection_type='equirectangular'), annotations = [dict( x=0.55, y=0.1, @@ -302,9 +294,7 @@ fig.update_layout( yref='paper', text='Source: \ CIA World Factbook', - showarrow = False - )] -) + showarrow = False)]) fig.show() ``` @@ -315,7 +305,6 @@ Plotly also includes a [legacy "figure factory" for creating US county-level cho ```python import plotly.figure_factory as ff - import numpy as np import pandas as pd @@ -326,13 +315,12 @@ df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code'] colorscale = ["#f7fbff", "#ebf3fb", "#deebf7", "#d2e3f3", "#c6dbef", "#b3d2e9", "#9ecae1", "#85bcdb", "#6baed6", "#57a0ce", "#4292c6", "#3082be", "#2171b5", "#1361a9", - "#08519c", "#0b4083", "#08306b" -] + "#08519c", "#0b4083", "#08306b"] + endpts = list(np.linspace(1, 12, len(colorscale) - 1)) fips = df_sample['FIPS'].tolist() values = df_sample['Unemployment Rate (%)'].tolist() - fig = ff.create_choropleth( fips=fips, values=values, scope=['usa'], binning_endpoints=endpts, colorscale=colorscale, @@ -340,8 +328,8 @@ fig = ff.create_choropleth( show_hover=True, asp = 2.9, title_text = 'USA by Unemployment %', - legend_title = '% unemployed' -) + legend_title = '% unemployed') + fig.layout.template = None fig.show() ``` diff --git a/doc/python/creating-and-updating-figures.md b/doc/python/creating-and-updating-figures.md index 89710a448a9..0dfcb699af6 100644 --- a/doc/python/creating-and-updating-figures.md +++ b/doc/python/creating-and-updating-figures.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -27,14 +27,14 @@ jupyter: language: python layout: base name: Creating and Updating Figures + order: 2 page_type: example_index permalink: python/creating-and-updating-figures/ redirect_from: - - python/user-guide/ - - python/user-g/ + - python/user-guide/ + - python/user-g/ thumbnail: thumbnail/creating-and-updating-figures.png v4upgrade: true - order: 2 --- ### Representing Figures @@ -79,12 +79,11 @@ Graph objects are stored in a hierarchy of modules under the `plotly.graph_objec ```python import plotly.graph_objects as go + fig = go.Figure( data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])], layout=go.Layout( - title=go.layout.Title(text="A Bar Chart") - ) -) + title=dict(text="A Bar Chart"))) fig.show() ``` @@ -271,31 +270,20 @@ Graph object figures support an `update_layout` method that may be used to updat ```python import plotly.graph_objects as go + fig = go.Figure(data=go.Bar(x=[1, 2, 3], y=[1, 3, 2])) -fig.update_layout(title_text="A Bar Chart", - title_font_size=30) +fig.update_layout(title=go.layout.Title(text="A Bar Chart", font=dict(size=30))) fig.show() ``` Note that the following `update_layout` operations are equivalent: ```python -fig.update_layout(title_text="A Bar Chart", - title_font_size=30) - -fig.update_layout(title_text="A Bar Chart", - title_font=dict(size=30)) - - -fig.update_layout(title=dict(text="A Bar Chart"), - font=dict(size=30)) - -fig.update_layout({"title": {"text": "A Bar Chart", - "font": {"size": 30}}}) - -fig.update_layout( - title=go.layout.Title(text="A Bar Chart", - font=go.layout.title.Font(size=30))); +fig.update_layout(title_text="A Bar Chart",title_font_size=30) +fig.update_layout(title_text="A Bar Chart", title_font=dict(size=30)) +fig.update_layout(title=dict(text="A Bar Chart"), font=dict(size=30)) +fig.update_layout({"title": {"text": "A Bar Chart", "font": {"size": 30}}}) +fig.update_layout(title=go.layout.Title(text="A Bar Chart", font=dict(size=30))) ``` #### The update traces method @@ -457,12 +445,9 @@ In the example below, the red color of markers is overwritten when updating `mar ```python import plotly.graph_objects as go -fig = go.Figure(go.Bar(x=[1, 2, 3], y=[6, 4, 9], - marker_color="red")) # will be overwritten below -fig.update_traces( - overwrite=True, - marker={"opacity": 0.4} - ) + +fig = go.Figure(go.Bar(x=[1, 2, 3], y=[6, 4, 9], marker_color="red")) # will be overwritten below +fig.update_traces(overwrite=True, marker={"opacity": 0.4}) fig.show() ``` @@ -477,12 +462,10 @@ Here is an example of using `for_each_trace` to replace the equal-sign with a co ```python import pandas as pd import plotly.express as px + df = px.data.iris() fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species") - -fig.for_each_trace( - lambda trace: trace.update(name=trace.name.replace("=", ": ")), -) +fig.for_each_trace(lambda trace: trace.update(name=trace.name.replace("=", ": "))) fig.show() ``` diff --git a/doc/python/custom-buttons.md b/doc/python/custom-buttons.md index db1a33e37ae..408ca6346df 100644 --- a/doc/python/custom-buttons.md +++ b/doc/python/custom-buttons.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.7 + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.7.2 + version: 3.7.3 plotly: description: How to add custom buttons to update Plotly chart attributes in Python. display_as: controls @@ -48,7 +48,6 @@ This example demonstrates how to update a single data attribute: chart `type` wi ```python import plotly.graph_objects as go - import pandas as pd # load dataset @@ -66,50 +65,30 @@ fig.update_layout( height=900, autosize=False, margin=dict(t=0, b=0, l=0, r=0), - template="plotly_white", -) + template="plotly_white") # Update 3D scene options -fig.update_scenes( - aspectratio=dict(x=1, y=1, z=0.7), - aspectmode="manual" -) +fig.update_scenes(aspectratio=dict(x=1, y=1, z=0.7), aspectmode="manual") # Add dropdown fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( type = "buttons", direction = "left", buttons=list([ - dict( - args=["type", "surface"], - label="3D Surface", - method="restyle" - ), - dict( - args=["type", "heatmap"], - label="Heatmap", - method="restyle" - ) - ]), + dict(args=["type", "surface"], label="3D Surface", method="restyle"), + dict(args=["type", "heatmap"], label="Heatmap", method="restyle")]), pad={"r": 10, "t": 10}, showactive=True, x=0.11, xanchor="left", y=1.1, - yanchor="top" - ), - ] -) + yanchor="top")]) # Add annotation -fig.update_layout( - annotations=[ - go.layout.Annotation(text="Trace type:", showarrow=False, - x=0, y=1.08, yref="paper", align="left") - ] -) +fig.update_layout(annotations=[ + dict(text="Trace type:", showarrow=False, x=0, y=1.08, yref="paper", align="left")]) fig.show() ``` @@ -137,14 +116,12 @@ fig.update_layout( width=800, height=900, autosize=False, - margin=dict(t=100, b=0, l=0, r=0), -) + margin=dict(t=100, b=0, l=0, r=0)) # Update 3D scene options fig.update_scenes( aspectratio=dict(x=1, y=1, z=0.7), - aspectmode="manual" -) + aspectmode="manual") # Add drowdowns # button_layer_1_height = 1.08 @@ -153,29 +130,24 @@ button_layer_2_height = 1.065 fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( buttons=list([ dict( args=["colorscale", "Viridis"], label="Viridis", - method="restyle" - ), + method="restyle"), dict( args=["colorscale", "Cividis"], label="Cividis", - method="restyle" - ), + method="restyle"), dict( args=["colorscale", "Blues"], label="Blues", - method="restyle" - ), + method="restyle"), dict( args=["colorscale", "Greens"], label="Greens", - method="restyle" - ), - ]), + method="restyle")]), type = "buttons", direction="right", pad={"r": 10, "t": 10}, @@ -183,21 +155,17 @@ fig.update_layout( x=0.1, xanchor="left", y=button_layer_1_height, - yanchor="top" - ), - go.layout.Updatemenu( + yanchor="top"), + dict( buttons=list([ dict( args=["reversescale", False], label="False", - method="restyle" - ), + method="restyle"), dict( args=["reversescale", True], label="True", - method="restyle" - ) - ]), + method="restyle")]), type = "buttons", direction="right", pad={"r": 10, "t": 10}, @@ -205,21 +173,17 @@ fig.update_layout( x=0.13, xanchor="left", y=button_layer_2_height, - yanchor="top" - ), - go.layout.Updatemenu( + yanchor="top"), + dict( buttons=list([ dict( args=[{"contours.showlines": False, "type": "contour"}], label="Hide lines", - method="restyle" - ), + method="restyle"), dict( args=[{"contours.showlines": True, "type": "contour"}], label="Show lines", - method="restyle" - ), - ]), + method="restyle")]), type = "buttons", direction="right", pad={"r": 10, "t": 10}, @@ -227,20 +191,16 @@ fig.update_layout( x=0.5, xanchor="left", y=button_layer_2_height, - yanchor="top" - ), - ] -) + yanchor="top")]) fig.update_layout( annotations=[ - go.layout.Annotation(text="colorscale", x=0, xref="paper", y=1.1, yref="paper", + dict(text="colorscale", x=0, xref="paper", y=1.1, yref="paper", align="left", showarrow=False), - go.layout.Annotation(text="Reverse
Colorscale", x=0, xref="paper", y=1.06, + dict(text="Reverse
Colorscale", x=0, xref="paper", y=1.06, yref="paper", showarrow=False), - go.layout.Annotation(text="Lines", x=0.47, xref="paper", y=1.045, yref="paper", - showarrow=False) - ]) + dict(text="Lines", x=0.47, xref="paper", y=1.045, yref="paper", + showarrow=False)]) fig.show() ``` @@ -268,45 +228,22 @@ y2 = np.random.normal(4, 0.4, 200) fig = go.Figure() # Add traces -fig.add_trace( - go.Scatter( - x=x0, - y=y0, - mode="markers", - marker=dict(color="DarkOrange") - ) -) - -fig.add_trace( - go.Scatter( - x=x1, - y=y1, - mode="markers", - marker=dict(color="Crimson") - ) -) - -fig.add_trace( - go.Scatter( - x=x2, - y=y2, - mode="markers", - marker=dict(color="RebeccaPurple") - ) -) +fig.add_trace(go.Scatter(x=x0, y=y0, mode="markers", marker=dict(color="DarkOrange"))) +fig.add_trace(go.Scatter(x=x1, y=y1, mode="markers", marker=dict(color="Crimson"))) +fig.add_trace(go.Scatter(x=x2, y=y2, mode="markers", marker=dict(color="RebeccaPurple"))) # Add buttons that add shapes -cluster0 = [go.layout.Shape(type="circle", +cluster0 = [dict(type="circle", xref="x", yref="y", x0=min(x0), y0=min(y0), x1=max(x0), y1=max(y0), line=dict(color="DarkOrange"))] -cluster1 = [go.layout.Shape(type="circle", +cluster1 = [dict(type="circle", xref="x", yref="y", x0=min(x1), y0=min(y1), x1=max(x1), y1=max(y1), line=dict(color="Crimson"))] -cluster2 = [go.layout.Shape(type="circle", +cluster2 = [dict(type="circle", xref="x", yref="y", x0=min(x2), y0=min(y2), x1=max(x2), y1=max(y2), @@ -314,7 +251,7 @@ cluster2 = [go.layout.Shape(type="circle", fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( type="buttons", buttons=[ dict(label="None", @@ -331,18 +268,10 @@ fig.update_layout( args=["shapes", cluster2]), dict(label="All", method="relayout", - args=["shapes", cluster0 + cluster1 + cluster2]) - ], - ) - ] -) + args=["shapes", cluster0 + cluster1 + cluster2])])]) # Update remaining layout properties -fig.update_layout( - title_text="Highlight Clusters", - showlegend=False, -) - +fig.update_layout(title_text="Highlight Clusters", showlegend=False) fig.show() ``` @@ -352,7 +281,6 @@ This example demonstrates how to update which traces are displayed while simulan ```python import plotly.graph_objects as go - import pandas as pd # Load dataset @@ -366,10 +294,7 @@ fig = go.Figure() # Add Traces fig.add_trace( - go.Scatter(x=list(df.index), - y=list(df.High), - name="High", - line=dict(color="#33CFA5"))) + go.Scatter(x=list(df.index), y=list(df.High), name="High", line=dict(color="#33CFA5"))) fig.add_trace( go.Scatter(x=list(df.index), @@ -415,7 +340,7 @@ low_annotations = [dict(x="2015-05-01", fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( type="buttons", direction="right", active=0, @@ -441,17 +366,10 @@ fig.update_layout( method="update", args=[{"visible": [True, True, True, True]}, {"title": "Yahoo", - "annotations": high_annotations + low_annotations}]), - ]), - ) - ]) + "annotations": high_annotations + low_annotations}])]))]) # Set title -fig.update_layout( - title_text="Yahoo", - xaxis_domain=[0.05, 1.0] -) - +fig.update_layout(title_text="Yahoo", xaxis_domain=[0.05, 1.0]) fig.show() ``` diff --git a/doc/python/dendrogram.md b/doc/python/dendrogram.md index f31ad8dce6f..0b7a902c4c9 100644 --- a/doc/python/dendrogram.md +++ b/doc/python/dendrogram.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make a dendrogram in Python with Plotly. display_as: scientific diff --git a/doc/python/dropdowns.md b/doc/python/dropdowns.md index 0ed8bae636e..ffe54eb2524 100644 --- a/doc/python/dropdowns.md +++ b/doc/python/dropdowns.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to add dropdowns to update Plotly chart attributes in Python. display_as: controls @@ -50,7 +50,6 @@ This example demonstrates how to update a single data attribute: chart `type` wi ```python import plotly.graph_objects as go - import pandas as pd # load dataset @@ -72,15 +71,12 @@ fig.update_layout( ) # Update 3D scene options -fig.update_scenes( - aspectratio=dict(x=1, y=1, z=0.7), - aspectmode="manual" -) +fig.update_scenes(aspectratio=dict(x=1, y=1, z=0.7), aspectmode="manual") # Add dropdown fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( buttons=list([ dict( args=["type", "surface"], @@ -91,8 +87,7 @@ fig.update_layout( args=["type", "heatmap"], label="Heatmap", method="restyle" - ) - ]), + )]), direction="down", pad={"r": 10, "t": 10}, showactive=True, @@ -100,17 +95,11 @@ fig.update_layout( xanchor="left", y=1.1, yanchor="top" - ), - ] -) + )]) # Add annotation -fig.update_layout( - annotations=[ - go.layout.Annotation(text="Trace type:", showarrow=False, - x=0, y=1.085, yref="paper", align="left") - ] -) +fig.update_layout(annotations=[ + dict(text="Trace type:", showarrow=False, x=0, y=1.085, yref="paper", align="left")]) fig.show() ``` @@ -121,7 +110,6 @@ This example demonstrates how to update several data attributes: colorscale, col ```python import plotly.graph_objects as go - import pandas as pd # load dataset @@ -138,104 +126,82 @@ fig.update_layout( width=800, height=900, autosize=False, - margin=dict(t=100, b=0, l=0, r=0), -) + margin=dict(t=100, b=0, l=0, r=0)) # Update 3D scene options fig.update_scenes( aspectratio=dict(x=1, y=1, z=0.7), - aspectmode="manual" -) + aspectmode="manual") # Add drowdowns button_layer_1_height = 1.08 fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( buttons=list([ dict( args=["colorscale", "Viridis"], label="Viridis", - method="restyle" - ), + method="restyle"), dict( args=["colorscale", "Cividis"], label="Cividis", - method="restyle" - ), + method="restyle"), dict( args=["colorscale", "Blues"], label="Blues", - method="restyle" - ), + method="restyle"), dict( args=["colorscale", "Greens"], label="Greens", - method="restyle" - ), - ]), + method="restyle")]), direction="down", pad={"r": 10, "t": 10}, showactive=True, x=0.1, xanchor="left", y=button_layer_1_height, - yanchor="top" - ), - go.layout.Updatemenu( + yanchor="top"), + dict( buttons=list([ dict( args=["reversescale", False], label="False", - method="restyle" - ), + method="restyle"), dict( args=["reversescale", True], label="True", - method="restyle" - ) - ]), + method="restyle")]), direction="down", pad={"r": 10, "t": 10}, showactive=True, x=0.37, xanchor="left", y=button_layer_1_height, - yanchor="top" - ), - go.layout.Updatemenu( + yanchor="top"), + dict( buttons=list([ dict( args=[{"contours.showlines": False, "type": "contour"}], label="Hide lines", - method="restyle" - ), + method="restyle"), dict( args=[{"contours.showlines": True, "type": "contour"}], label="Show lines", - method="restyle" - ), - ]), + method="restyle")]), direction="down", pad={"r": 10, "t": 10}, showactive=True, x=0.58, xanchor="left", y=button_layer_1_height, - yanchor="top" - ), - ] -) + yanchor="top")]) fig.update_layout( annotations=[ - go.layout.Annotation(text="colorscale", x=0, xref="paper", y=1.06, yref="paper", - align="left", showarrow=False), - go.layout.Annotation(text="Reverse
Colorscale", x=0.25, xref="paper", y=1.07, - yref="paper", showarrow=False), - go.layout.Annotation(text="Lines", x=0.54, xref="paper", y=1.06, yref="paper", - showarrow=False) - ]) + dict(text="colorscale", x=0, xref="paper", y=1.06, yref="paper", align="left", showarrow=False), + dict(text="Reverse
Colorscale", x=0.25, xref="paper", y=1.07, yref="paper", showarrow=False), + dict(text="Lines", x=0.54, xref="paper", y=1.06, yref="paper", showarrow=False)]) fig.show() ``` @@ -265,56 +231,39 @@ y2 = np.random.normal(4, 0.4, 200) fig = go.Figure() # Add traces -fig.add_trace( - go.Scatter( - x=x0, - y=y0, - mode="markers", - marker=dict(color="DarkOrange") - ) -) - -fig.add_trace( - go.Scatter( - x=x1, - y=y1, - mode="markers", - marker=dict(color="Crimson") - ) -) - -fig.add_trace( - go.Scatter( - x=x2, - y=y2, - mode="markers", - marker=dict(color="RebeccaPurple") - ) -) +fig.add_trace(go.Scatter(x=x0, y=y0, mode="markers", marker=dict(color="DarkOrange"))) +fig.add_trace(go.Scatter(x=x1, y=y1, mode="markers", marker=dict(color="Crimson"))) +fig.add_trace(go.Scatter(x=x2, y=y2, mode="markers", marker=dict(color="RebeccaPurple"))) # Add buttons that add shapes -cluster0 = [go.layout.Shape(type="circle", - xref="x", yref="y", - x0=min(x0), y0=min(y0), - x1=max(x0), y1=max(y0), - line=dict(color="DarkOrange"))] -cluster1 = [go.layout.Shape(type="circle", - xref="x", yref="y", - x0=min(x1), y0=min(y1), - x1=max(x1), y1=max(y1), - line=dict(color="Crimson"))] -cluster2 = [go.layout.Shape(type="circle", - xref="x", yref="y", - x0=min(x2), y0=min(y2), - x1=max(x2), y1=max(y2), - line=dict(color="RebeccaPurple"))] +cluster0 = [dict( + type="circle", + xref="x", yref="y", + x0=min(x0), y0=min(y0), + x1=max(x0), y1=max(y0), + line=dict(color="DarkOrange"))] + +cluster1 = [dict( + type="circle", + xref="x", yref="y", + x0=min(x1), y0=min(y1), + x1=max(x1), y1=max(y1), + line=dict(color="Crimson"))] + +cluster2 = [dict( + type="circle", + xref="x", yref="y", + x0=min(x2), y0=min(y2), + x1=max(x2), y1=max(y2), + line=dict(color="RebeccaPurple"))] fig.update_layout( - updatemenus=[ - go.layout.Updatemenu(buttons=list([ - dict(label="None", - method="relayout", - args=["shapes", []]), + updatemenus=[dict( + buttons=list([ + dict( + label="None", + method="relayout", + args=["shapes", []]), dict(label="Cluster 0", method="relayout", args=["shapes", cluster0]), @@ -326,17 +275,8 @@ fig.update_layout( args=["shapes", cluster2]), dict(label="All", method="relayout", - args=["shapes", cluster0 + cluster1 + cluster2]) - ]), - ) - ] -) - -# Update remaining layout properties -fig.update_layout( - title_text="Highlight Clusters", - showlegend=False, -) + args=["shapes", cluster0 + cluster1 + cluster2])]))], + title_text="Highlight Clusters", showlegend=False) fig.show() ``` @@ -348,44 +288,23 @@ This example demonstrates how to update which traces are displayed while simulan ```python import plotly.graph_objects as go - import pandas as pd # Load dataset -df = pd.read_csv( - "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") +df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") df.columns = [col.replace("AAPL.", "") for col in df.columns] # Initialize figure fig = go.Figure() # Add Traces +fig.add_trace(go.Scatter(x=list(df.index), y=list(df.High), name="High", line=dict(color="#33CFA5"))) +fig.add_trace(go.Scatter(x=list(df.index), y=[df.High.mean()] * len(df.index), + name="High Average", visible=False, line=dict(color="#33CFA5", dash="dash"))) -fig.add_trace( - go.Scatter(x=list(df.index), - y=list(df.High), - name="High", - line=dict(color="#33CFA5"))) - -fig.add_trace( - go.Scatter(x=list(df.index), - y=[df.High.mean()] * len(df.index), - name="High Average", - visible=False, - line=dict(color="#33CFA5", dash="dash"))) - -fig.add_trace( - go.Scatter(x=list(df.index), - y=list(df.Low), - name="Low", - line=dict(color="#F06A6A"))) - -fig.add_trace( - go.Scatter(x=list(df.index), - y=[df.Low.mean()] * len(df.index), - name="Low Average", - visible=False, - line=dict(color="#F06A6A", dash="dash"))) +fig.add_trace(go.Scatter(x=list(df.index), y=list(df.Low), name="Low", line=dict(color="#F06A6A"))) +fig.add_trace(go.Scatter(x=list(df.index), y=[df.Low.mean()] * len(df.index), + name="Low Average", visible=False, line=dict(color="#F06A6A", dash="dash"))) # Add Annotations and Buttons high_annotations = [dict(x="2016-03-01", @@ -411,7 +330,7 @@ low_annotations = [dict(x="2015-05-01", fig.update_layout( updatemenus=[ - go.layout.Updatemenu( + dict( active=0, buttons=list([ dict(label="None", @@ -433,13 +352,8 @@ fig.update_layout( method="update", args=[{"visible": [True, True, True, True]}, {"title": "Yahoo", - "annotations": high_annotations + low_annotations}]), - ]), - ) - ]) - -# Set title -fig.update_layout(title_text="Yahoo") + "annotations": high_annotations + low_annotations}])]))], + title_text="Yahoo") fig.show() ``` diff --git a/doc/python/images.md b/doc/python/images.md index 4bf287df16c..a97692dca28 100644 --- a/doc/python/images.md +++ b/doc/python/images.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.1' - jupytext_version: 1.1.1 + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -38,9 +38,9 @@ jupyter: In this page we explain how to add static, non-interactive images as background, logo or annotation images to a figure. For exploring image data in interactive charts, see the [tutorial on displaying image data](/python/imshow). A background image can be added to the layout of a figure with -`fig.add_layout_image` or by setting the `images` parameter of `go.Layout`. The -`source` attribute of a `go.layout.Image` can be the URL of an image, or a PIL -Image object (`from PIL import Image; img = Image.open('filename.png')`). +`fig.add_layout_image`. The +`source` attribute can be the URL of an image, or a PIL +Image object (`from PIL import Image; img = Image.open('path-to-your-file/filename.png')`). ```python import plotly.graph_objects as go @@ -49,28 +49,20 @@ import plotly.graph_objects as go fig = go.Figure() # Add trace -fig.add_trace( - go.Scatter(x=[0, 0.5, 1, 2, 2.2], y=[1.23, 2.5, 0.42, 3, 1]) -) +fig.add_trace(go.Scatter(x=[0, 0.5, 1, 2, 2.2], y=[1.23, 2.5, 0.42, 3, 1])) # Add images fig.add_layout_image( - go.layout.Image( - source="https://images.plot.ly/language-icons/api-home/python-logo.png", - xref="x", - yref="y", - x=0, - y=3, - sizex=2, - sizey=2, - sizing="stretch", - opacity=0.5, - layer="below") -) + source="https://images.plot.ly/language-icons/api-home/python-logo.png", + xref="x", yref="y", + x=0, y=3, + sizex=2, sizey=2, + sizing="stretch", + opacity=0.5, + layer="below") # Set templates fig.update_layout(template="plotly_white") - fig.show() ``` @@ -81,7 +73,6 @@ See more examples of [adding logos to charts](https://plot.ly/python/logos/)! import plotly.graph_objects as go fig = go.Figure() - fig.add_trace( go.Bar( x=["-35.3", "-15.9", "-15.8", "-15.6", "-11.1", @@ -108,14 +99,9 @@ fig.add_trace( "Nurses", "Legal support workers", "Computer programmers and system admin.", "Police officers and firefighters", "Chief executives", "Doctors, dentists and surgeons"], - marker=go.bar.Marker( - color="rgb(253, 240, 54)", - line=dict(color="rgb(0, 0, 0)", - width=2) - ), - orientation="h", - ) -) + marker=go.bar.Marker(color="rgb(253, 240, 54)", + line=dict(color="rgb(0, 0, 0)", width=2)), + orientation="h")) # Add image fig.add_layout_image( @@ -124,9 +110,7 @@ fig.add_layout_image( xref="paper", yref="paper", x=1, y=1.05, sizex=0.2, sizey=0.2, - xanchor="right", yanchor="bottom" - ) -) + xanchor="right", yanchor="bottom")) # update layout properties fig.update_layout( @@ -139,8 +123,7 @@ fig.update_layout( hovermode="x", margin=dict(r=20, l=300, b=75, t=125), title=("Moving Up, Moving Down
" + - "Percentile change in income between childhood and adulthood"), -) + "Percentile change in income between childhood and adulthood")) fig.show() ``` @@ -178,41 +161,30 @@ for (x, y), n in zip(simulated_absorptions, names): # Add images fig.add_layout_image( - go.layout.Image( source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/benzene.png", - x=0.75, - y=0.65, - )) -fig.add_layout_image(go.layout.Image( + x=0.75, y=0.65) +fig.add_layout_image( source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/naphthalene.png", - x=0.9, - y=0.3, - ) -) + x=0.9, y=0.3) + fig.update_layout_images(dict( - xref="paper", - yref="paper", - sizex=0.3, - sizey=0.3, - xanchor="right", - yanchor="bottom" -)) + xref="paper", yref="paper", + sizex=0.3, sizey=0.3, + xanchor="right", yanchor="bottom")) # Add annotations fig.update_layout( annotations=[ - go.layout.Annotation( - x=93.0 / 300, + dict( + x=93.0 / 300, y=0.07 / 0.1, - xref="paper", + xref="paper", yref="paper", showarrow=True, arrowhead=0, opacity=0.5, - ax=250, - ay=-40, - ), - go.layout.Annotation( + ax=250, ay=-40), + dict( x=156.0 / 300, y=0.04 / 0.1, xref="paper", @@ -221,10 +193,7 @@ fig.update_layout( arrowhead=0, opacity=0.5, ax=140, - ay=-10, - ) - ] -) + ay=-10)]) # Configure axes fig.update_xaxes(title_text="Wavelength") @@ -235,8 +204,7 @@ fig.update_layout( title_text="Absorption Frequencies of Benzene and Naphthalene", height=500, width=900, - template="plotly_white" -) + template="plotly_white") fig.show() ``` @@ -261,44 +229,32 @@ fig.add_trace( x=[0, img_width * scale_factor], y=[0, img_height * scale_factor], mode="markers", - marker_opacity=0 - ) -) + marker_opacity=0)) # Configure axes -fig.update_xaxes( - visible=False, - range=[0, img_width * scale_factor] -) - -fig.update_yaxes( - visible=False, - range=[0, img_height * scale_factor], +fig.update_xaxes(visible=False, range=[0, img_width * scale_factor]) +fig.update_yaxes(visible=False, range=[0, img_height * scale_factor], # the scaleanchor attribute ensures that the aspect ratio stays constant - scaleanchor="x" -) + scaleanchor="x") # Add image fig.add_layout_image( - go.layout.Image( x=0, sizex=img_width * scale_factor, y=img_height * scale_factor, sizey=img_height * scale_factor, - xref="x", + xref="x", yref="y", opacity=1.0, layer="below", sizing="stretch", source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/bridge.jpg") -) # Configure other layout fig.update_layout( width=img_width * scale_factor, height=img_height * scale_factor, - margin={"l": 0, "r": 0, "t": 0, "b": 0}, -) + margin={"l": 0, "r": 0, "t": 0, "b": 0}) # Disable the autosize on double click because it adds unwanted margins around the image # More detail: https://plot.ly/python/configuration-options/ diff --git a/doc/python/lines-on-maps.md b/doc/python/lines-on-maps.md index 514a6a51e1a..69bbaa2c01b 100644 --- a/doc/python/lines-on-maps.md +++ b/doc/python/lines-on-maps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.1' + jupytext_version: 1.2.1 kernelspec: display_name: Python 3 language: python @@ -75,14 +75,8 @@ fig.add_trace(go.Scattergeo( hoverinfo = 'text', text = df_airports['airport'], mode = 'markers', - marker = dict( - size = 2, - color = 'rgb(255, 0, 0)', - line = dict( - width = 3, - color = 'rgba(68, 68, 68, 0)' - ) - ))) + marker = dict(size = 2, color = 'rgb(255, 0, 0)', + line = dict(width = 3, color = 'rgba(68, 68, 68, 0)')))) flight_paths = [] for i in range(len(df_flight_paths)): @@ -93,21 +87,17 @@ for i in range(len(df_flight_paths)): lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]], mode = 'lines', line = dict(width = 1,color = 'red'), - opacity = float(df_flight_paths['cnt'][i]) / float(df_flight_paths['cnt'].max()), - ) - ) + opacity = float(df_flight_paths['cnt'][i]) / float(df_flight_paths['cnt'].max()))) fig.update_layout( title_text = 'Feb. 2011 American Airline flight paths
(Hover for airport names)', showlegend = False, - geo = go.layout.Geo( + geo = dict( scope = 'north america', projection_type = 'azimuthal equal area', showland = True, landcolor = 'rgb(243, 243, 243)', - countrycolor = 'rgb(204, 204, 204)', - ), -) + countrycolor = 'rgb(204, 204, 204)')) fig.show() ``` diff --git a/doc/python/mapbox-layers.md b/doc/python/mapbox-layers.md index 0aac4981c1a..5085c903dc0 100644 --- a/doc/python/mapbox-layers.md +++ b/doc/python/mapbox-layers.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.2" - jupytext_version: 1.3.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.8 + version: 3.7.3 plotly: description: How to make Mapbox maps in Python with various base layers, with @@ -35,7 +35,6 @@ jupyter: thumbnail: thumbnail/mapbox-layers.png --- - ### Mapbox Maps vs Geo Maps @@ -74,7 +73,6 @@ The accepted values for `layout.mapbox.style` are one of: Here is a simple map rendered with OpenStreetMaps tiles, without needing a Mapbox Access Token: - ```python import pandas as pd @@ -89,7 +87,6 @@ fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) fig.show() ``` - #### Using `layout.mapbox.layers` to Specify a Base Map @@ -101,7 +98,6 @@ If you have access to your own private tile servers, or wish to use a tile serve Here is an example of a map which uses a public USGS imagery map, specified in `layout.mapbox.layers`, and which is rendered _below_ the `data` layer. - ```python import pandas as pd @@ -126,13 +122,11 @@ fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) fig.show() ``` - #### Base Tiles from the USGS, radar overlay from Environment Canada: no token needed Here is the same example, with in addition, a WMS layer from Environment Canada which displays near-real-time radar imagery in partly-transparent raster tiles, rendered above the `go.Scattermapbox` trace, as is the default: - ```python import pandas as pd @@ -163,13 +157,11 @@ fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) fig.show() ``` - #### Dark tiles from Mapbox service: free token needed Here is a map rendered with the `"dark"` style from the Mapbox service, which requires an Access Token: - ```python token = open(".mapbox_token").read() # you will need your own token diff --git a/doc/python/marker-style.md b/doc/python/marker-style.md index e456d7f41f9..67b4cb24c60 100644 --- a/doc/python/marker-style.md +++ b/doc/python/marker-style.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.7 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.5 + version: 3.7.3 plotly: description: How to style markers in Python with Plotly. display_as: file_settings diff --git a/doc/python/mixed-subplots.md b/doc/python/mixed-subplots.md index 6e5cf625d40..c211475d0b1 100644 --- a/doc/python/mixed-subplots.md +++ b/doc/python/mixed-subplots.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.6 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -38,14 +38,12 @@ jupyter: ```python import plotly.graph_objects as go from plotly.subplots import make_subplots - import pandas as pd # read in volcano database data df = pd.read_csv( "https://raw.githubusercontent.com/plotly/datasets/master/volcano_db.csv", - encoding="iso-8859-1", -) + encoding="iso-8859-1") # frequency of Country freq = df @@ -70,20 +68,15 @@ fig.add_trace( hoverinfo="text", showlegend=False, marker=dict(color="crimson", size=4, opacity=0.8)), - row=1, col=1 -) + row=1, col=1) # Add locations bar chart fig.add_trace( go.Bar(x=freq["x"][0:10],y=freq["Country"][0:10], marker=dict(color="crimson"), showlegend=False), - row=1, col=2 -) + row=1, col=2) # Add 3d surface of volcano -fig.add_trace( - go.Surface(z=df_v.values.tolist(), showscale=False), - row=2, col=2 -) +fig.add_trace(go.Surface(z=df_v.values.tolist(), showscale=False), row=2, col=2) # Update geo subplot properties fig.update_geos( @@ -91,8 +84,7 @@ fig.update_geos( landcolor="white", oceancolor="MidnightBlue", showocean=True, - lakecolor="LightBlue" -) + lakecolor="LightBlue") # Rotate x-axis labels fig.update_xaxes(tickangle=45) @@ -101,17 +93,13 @@ fig.update_xaxes(tickangle=45) fig.update_layout( template="plotly_dark", margin=dict(r=10, t=25, b=40, l=60), - annotations=[ - go.layout.Annotation( - text="Source: NOAA", - showarrow=False, - xref="paper", - yref="paper", - x=0, - y=0) - ] -) - + annotations=[dict( + text="Source: NOAA", + showarrow=False, + xref="paper", + yref="paper", + x=0, + y=0)]) fig.show() ``` diff --git a/doc/python/radar-chart.md b/doc/python/radar-chart.md index a180a8ee74e..37a9c187606 100644 --- a/doc/python/radar-chart.md +++ b/doc/python/radar-chart.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make radar charts in Python with Plotly. display_as: scientific diff --git a/doc/python/random-walk.md b/doc/python/random-walk.md index 11867ddb80e..212b7f4030b 100644 --- a/doc/python/random-walk.md +++ b/doc/python/random-walk.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: Learn how to use Python to make a Random Walk display_as: advanced_opt diff --git a/doc/python/range-slider.md b/doc/python/range-slider.md index 63b65a20a08..d09223b9717 100644 --- a/doc/python/range-slider.md +++ b/doc/python/range-slider.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.7 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.7.2 + version: 3.7.3 plotly: description: Now you can implement range sliders and selectors in your Plotly graphs purely with python! @@ -48,18 +48,14 @@ df.columns = [col.replace("AAPL.", "") for col in df.columns] # Create figure fig = go.Figure() - -fig.add_trace( - go.Scatter(x=list(df.Date), y=list(df.High))) +fig.add_trace(go.Scatter(x=list(df.Date), y=list(df.High))) # Set title -fig.update_layout( - title_text="Time series with range slider and selectors" -) +fig.update_layout(title_text="Time series with range slider and selectors") # Add range slider fig.update_layout( - xaxis=go.layout.XAxis( + xaxis=dict( rangeselector=dict( buttons=list([ dict(count=1, @@ -78,15 +74,9 @@ fig.update_layout( label="1y", step="year", stepmode="backward"), - dict(step="all") - ]) - ), - rangeslider=dict( - visible=True - ), - type="date" - ) -) + dict(step="all")])), + rangeslider=dict(visible=True), + type="date")) fig.show() ``` @@ -111,31 +101,26 @@ fig.add_trace(go.Scatter( name="var0", text=["8", "3", "2", "10", "5", "5", "6", "8", "3", "3", "7", "5", "10", "10", "9", "14"], - yaxis="y", -)) + yaxis="y")) fig.add_trace(go.Scatter( x=["2015-04-13", "2015-05-13", "2015-06-08", "2015-08-05", "2016-02-25"], y=["53.0", "69.0", "89.0", "41.0", "41.0"], name="var1", text=["53.0", "69.0", "89.0", "41.0", "41.0"], - yaxis="y2", -)) + yaxis="y2")) fig.add_trace(go.Scatter( x=["2013-01-29", "2013-02-26", "2013-04-19", "2013-07-02", "2013-08-27", "2013-10-22", "2014-01-20", "2014-04-09", "2014-05-05", "2014-07-01", "2014-09-30", - "2015-02-09", - "2015-04-13", "2015-06-08", "2016-02-25"], + "2015-02-09", "2015-04-13", "2015-06-08", "2016-02-25"], y=["9.6", "4.6", "2.7", "8.3", "18", "7.3", "3", "7.5", "1.0", "0.5", "2.8", "9.2", "13", "5.8", "6.9"], name="var2", text=["9.6", "4.6", "2.7", "8.3", "18", "7.3", "3", "7.5", "1.0", "0.5", "2.8", - "9.2", - "13", "5.8", "6.9"], - yaxis="y3", -)) + "9.2", "13", "5.8", "6.9"], + yaxis="y3")) fig.add_trace(go.Scatter( x=["2013-01-29", "2013-02-26", "2013-04-19", "2013-07-02", "2013-08-27", @@ -147,10 +132,8 @@ fig.add_trace(go.Scatter( "7.2", "7.2", "8.0"], name="var3", text=["6.9", "7.5", "7.3", "7.3", "6.9", "7.1", "8", "7.8", "7.4", "7.9", "7.9", - "7.6", - "7.2", "7.2", "8.0"], - yaxis="y4", -)) + "7.6", "7.2", "7.2", "8.0"], + yaxis="y4")) fig.add_trace(go.Scatter( x=["2013-02-26", "2013-07-02", "2013-09-26", "2013-10-22", "2013-12-04", @@ -159,8 +142,7 @@ fig.add_trace(go.Scatter( y=["290", "1078", "263", "407", "660", "740", "33", "374", "95", "734", "3000"], name="var4", text=["290", "1078", "263", "407", "660", "740", "33", "374", "95", "734", "3000"], - yaxis="y5", -)) + yaxis="y5")) # style all the traces fig.update_traces( @@ -168,13 +150,12 @@ fig.update_traces( line={"width": 0.5}, marker={"size": 8}, mode="lines+markers", - showlegend=False -) + showlegend=False) # Add annotations fig.update_layout( annotations=[ - go.layout.Annotation( + dict( x="2013-06-01", y=0, arrowcolor="rgba(63, 81, 181, 0.2)", @@ -184,9 +165,8 @@ fig.update_layout( text="state1", xref="x", yanchor="bottom", - yref="y" - ), - go.layout.Annotation( + yref="y"), + dict( x="2014-09-13", y=0, arrowcolor="rgba(76, 175, 80, 0.1)", @@ -196,15 +176,12 @@ fig.update_layout( text="state2", xref="x", yanchor="bottom", - yref="y" - ) - ], -) + yref="y")]) # Add shapes fig.update_layout( shapes=[ - go.layout.Shape( + dict( fillcolor="rgba(63, 81, 181, 0.2)", line={"width": 0}, type="rect", @@ -213,9 +190,8 @@ fig.update_layout( xref="x", y0=0, y1=0.95, - yref="paper" - ), - go.layout.Shape( + yref="paper"), + dict( fillcolor="rgba(76, 175, 80, 0.1)", line={"width": 0}, type="rect", @@ -224,23 +200,18 @@ fig.update_layout( xref="x", y0=0, y1=0.95, - yref="paper" - ) - ] -) + yref="paper")]) # Update axes fig.update_layout( - xaxis=go.layout.XAxis( + xaxis=dict( autorange=True, range=["2012-10-31 18:36:37.3129", "2016-05-10 05:23:22.6871"], rangeslider=dict( autorange=True, - range=["2012-10-31 18:36:37.3129", "2016-05-10 05:23:22.6871"] - ), - type="date" - ), - yaxis=go.layout.YAxis( + range=["2012-10-31 18:36:37.3129", "2016-05-10 05:23:22.6871"]), + type="date"), + yaxis=dict( anchor="x", autorange=True, domain=[0, 0.2], @@ -254,9 +225,8 @@ fig.update_layout( ticks="", titlefont={"color": "#673ab7"}, type="linear", - zeroline=False - ), - yaxis2=go.layout.YAxis( + zeroline=False), + yaxis2=dict( anchor="x", autorange=True, domain=[0.2, 0.4], @@ -270,9 +240,8 @@ fig.update_layout( ticks="", titlefont={"color": "#E91E63"}, type="linear", - zeroline=False - ), - yaxis3=go.layout.YAxis( + zeroline=False), + yaxis3=dict( anchor="x", autorange=True, domain=[0.4, 0.6], @@ -287,9 +256,8 @@ fig.update_layout( title="mg/L", titlefont={"color": "#795548"}, type="linear", - zeroline=False - ), - yaxis4=go.layout.YAxis( + zeroline=False), + yaxis4=dict( anchor="x", autorange=True, domain=[0.6, 0.8], @@ -304,9 +272,8 @@ fig.update_layout( title="mmol/L", titlefont={"color": "#607d8b"}, type="linear", - zeroline=False - ), - yaxis5=go.layout.YAxis( + zeroline=False), + yaxis5=dict( anchor="x", autorange=True, domain=[0.8, 1], @@ -321,9 +288,7 @@ fig.update_layout( title="mg/Kg", titlefont={"color": "#2196F3"}, type="linear", - zeroline=False - ) -) + zeroline=False)) # Update layout fig.update_layout( @@ -332,11 +297,7 @@ fig.update_layout( legend=dict(traceorder="reversed"), height=600, template="plotly_white", - margin=dict( - t=100, - b=100 - ), -) + margin=dict(t=100, b=100)) fig.show() ``` diff --git a/doc/python/scatter-plots-on-maps.md b/doc/python/scatter-plots-on-maps.md index be23088be84..b9aededd372 100644 --- a/doc/python/scatter-plots-on-maps.md +++ b/doc/python/scatter-plots-on-maps.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,10 +20,9 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: - description: - How to make scatter plots on maps in Python. Scatter plots on maps + description: How to make scatter plots on maps in Python. Scatter plots on maps highlight geographic areas and can be colored by value. display_as: maps language: python diff --git a/doc/python/scattermapbox.md b/doc/python/scattermapbox.md index 0f9a32aea2e..a9c3aebeb72 100644 --- a/doc/python/scattermapbox.md +++ b/doc/python/scattermapbox.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.8 + version: 3.7.3 plotly: description: How to make scatter plots on Mapbox maps in Python. display_as: maps @@ -58,31 +58,21 @@ fig.show() import plotly.graph_objects as go mapbox_access_token = open(".mapbox_token").read() - fig = go.Figure(go.Scattermapbox( lat=['45.5017'], lon=['-73.5673'], mode='markers', - marker=go.scattermapbox.Marker( - size=14 - ), - text=['Montreal'], - )) + marker=dict(size=14), + text=['Montreal'])) fig.update_layout( hovermode='closest', - mapbox=go.layout.Mapbox( + mapbox=dict( accesstoken=mapbox_access_token, bearing=0, - center=go.layout.mapbox.Center( - lat=45, - lon=-73 - ), + center=dict(lat=45, lon=-73), pitch=0, - zoom=5 - ) -) - + zoom=5)) fig.show() ``` @@ -94,41 +84,32 @@ import plotly.graph_objects as go mapbox_access_token = open(".mapbox_token").read() fig = go.Figure(go.Scattermapbox( - lat=['38.91427','38.91538','38.91458', + lat=['38.91427','38.91538','38.91458', '38.92239','38.93222','38.90842', '38.91931','38.93260','38.91368', '38.88516','38.921894','38.93206', '38.91275'], - lon=['-77.02827','-77.02013','-77.03155', + lon=['-77.02827','-77.02013','-77.03155', '-77.04227','-77.02854','-77.02419', '-77.02518','-77.03304','-77.04509', '-76.99656','-77.042438','-77.02821', '-77.01239'], - mode='markers', - marker=go.scattermapbox.Marker( - size=9 - ), - text=["The coffee bar","Bistro Bohem","Black Cat", - "Snap","Columbia Heights Coffee","Azi's Cafe", - "Blind Dog Cafe","Le Caprice","Filter", - "Peregrine","Tryst","The Coupe", - "Big Bear Cafe"], - )) + mode='markers', + marker=dict(size=9), + text=["The coffee bar","Bistro Bohem","Black Cat", + "Snap","Columbia Heights Coffee","Azi's Cafe", + "Blind Dog Cafe","Le Caprice","Filter", + "Peregrine","Tryst","The Coupe", "Big Bear Cafe"])) fig.update_layout( autosize=True, hovermode='closest', - mapbox=go.layout.Mapbox( + mapbox=dict( accesstoken=mapbox_access_token, bearing=0, - center=go.layout.mapbox.Center( - lat=38.92, - lon=-77.07 - ), + center=dict(lat=38.92, lon=-77.07), pitch=0, - zoom=10 - ), -) + zoom=10)) fig.show() ``` @@ -147,49 +128,33 @@ site_lon = df.lon locations_name = df.text fig = go.Figure() - fig.add_trace(go.Scattermapbox( lat=site_lat, lon=site_lon, mode='markers', - marker=go.scattermapbox.Marker( - size=17, - color='rgb(255, 0, 0)', - opacity=0.7 - ), + marker=dict(size=17, color='rgb(255, 0, 0)', opacity=0.7), text=locations_name, - hoverinfo='text' - )) + hoverinfo='text')) fig.add_trace(go.Scattermapbox( lat=site_lat, lon=site_lon, mode='markers', - marker=go.scattermapbox.Marker( - size=8, - color='rgb(242, 177, 172)', - opacity=0.7 - ), - hoverinfo='none' - )) + marker=dict(size=8, color='rgb(242, 177, 172)', opacity=0.7), + hoverinfo='none')) fig.update_layout( title='Nuclear Waste Sites on Campus', autosize=True, hovermode='closest', showlegend=False, - mapbox=go.layout.Mapbox( + mapbox=dict( accesstoken=mapbox_access_token, bearing=0, - center=go.layout.mapbox.Center( - lat=38, - lon=-94 - ), + center=dict(lat=38, lon=-94), pitch=0, zoom=3, - style='light' - ), -) + style='light')) fig.show() ``` @@ -212,16 +177,14 @@ import plotly.graph_objects as go token = open(".mapbox_token").read() # you need your own token fig = go.Figure(go.Scattermapbox( - mode = "markers+text+lines", - lon = [-75, -80, -50], lat = [45, 20, -20], - marker = {'size': 20, 'symbol': ["bus", "harbor", "airport"]}, - text = ["Bus", "Harbor", "airport"],textposition = "bottom right")) + mode="markers+text+lines", + lon=[-75, -80, -50], lat=[45, 20, -20], + marker={'size': 20, 'symbol': ["bus", "harbor", "airport"]}, + text=["Bus", "Harbor", "airport"],textposition = "bottom right")) fig.update_layout( - mapbox = { - 'accesstoken': token, - 'style': "outdoors", 'zoom': 0.7}, - showlegend = False) + mapbox={'accesstoken': token, 'style': "outdoors", 'zoom': 0.7}, + showlegend=False) fig.show() ``` diff --git a/doc/python/setting-graph-size.md b/doc/python/setting-graph-size.md index a2d3e51821d..a1ce0511047 100644 --- a/doc/python/setting-graph-size.md +++ b/doc/python/setting-graph-size.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.7 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.5 + version: 3.7.3 plotly: description: How to manipulate the graph size in Python with Plotly. display_as: file_settings @@ -43,8 +43,7 @@ fig = px.scatter(df, x="total_bill", y="tip", facet_col="sex", fig.update_layout( margin=dict(l=20, r=20, t=20, b=20), - paper_bgcolor="LightSteelBlue", -) + paper_bgcolor="LightSteelBlue") fig.show() ``` @@ -55,25 +54,16 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - fig.add_trace(go.Scatter( x=[0, 1, 2, 3, 4, 5, 6, 7, 8], - y=[0, 1, 2, 3, 4, 5, 6, 7, 8] -)) + y=[0, 1, 2, 3, 4, 5, 6, 7, 8])) fig.update_layout( autosize=False, width=500, height=500, - margin=go.layout.Margin( - l=50, - r=50, - b=100, - t=100, - pad=4 - ), - paper_bgcolor="LightSteelBlue", -) + margin=dict(l=50, r=50, b=100, t=100, pad=4), + paper_bgcolor="LightSteelBlue") fig.show() ``` @@ -85,29 +75,23 @@ Set [automargin](https://plot.ly/python/reference/#layout-xaxis-automargin) to ` ```python import plotly.graph_objects as go - fig = go.Figure() - fig.add_trace(go.Bar( x=["Apples", "Oranges", "Watermelon", "Pears"], - y=[3, 2, 1, 4] -)) + y=[3, 2, 1, 4])) fig.update_layout( autosize=False, width=500, height=500, - yaxis=go.layout.YAxis( + yaxis=dict( title_text="Y-axis Title", ticktext=["Very long label", "long label", "3", "label"], tickvals=[1, 2, 3, 4], tickmode="array", - titlefont=dict(size=30), - ) -) + titlefont=dict(size=30))) fig.update_yaxes(automargin=True) - fig.show() ``` diff --git a/doc/python/shapes.md b/doc/python/shapes.md index d0ae16b9e7d..8f635023f98 100644 --- a/doc/python/shapes.md +++ b/doc/python/shapes.md @@ -59,16 +59,11 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Create scatter trace of text labels fig.add_trace(go.Scatter( - x=[2, 3.5, 6], - y=[1, 1.5, 1], - text=["Vertical Line", - "Horizontal Dashed Line", - "Diagonal dotted Line"], - mode="text", -)) + x=[2, 3.5, 6], y=[1, 1.5, 1], + text=["Vertical Line", "Horizontal Dashed Line", "Diagonal dotted Line"], + mode="text")) # Set axes ranges fig.update_xaxes(range=[0, 7]) @@ -76,46 +71,23 @@ fig.update_yaxes(range=[0, 2.5]) # Add shapes fig.add_shape( - # Line Vertical - go.layout.Shape( - type="line", - x0=1, - y0=0, - x1=1, - y1=2, - line=dict( - color="RoyalBlue", - width=3 - ) -)) -fig.add_shape( - # Line Horizontal - go.layout.Shape( - type="line", - x0=2, - y0=2, - x1=5, - y1=2, - line=dict( - color="LightSeaGreen", - width=4, - dash="dashdot", - ), - )) + # Line Vertical + type="line", + x0=1, y0=0, x1=1, y1=2, + line=dict(color="RoyalBlue", width=3)) + +fig.add_shape( + # Line Horizontal + type="line", + x0=2, y0=2, x1=5, y1=2, + line=dict(color="LightSeaGreen", width=4, dash="dashdot")) + fig.add_shape( - # Line Diagonal - go.layout.Shape( - type="line", - x0=4, - y0=0, - x1=6, - y1=2, - line=dict( - color="MediumPurple", - width=4, - dash="dot", - ) -)) + # Line Diagonal + type="line", + x0=4, y0=0, x1=6, y1=2, + line=dict(color="MediumPurple", width=4, dash="dot")) + fig.update_shapes(dict(xref='x', yref='y')) fig.show() ``` @@ -126,15 +98,10 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Create scatter trace of text labels fig.add_trace(go.Scatter( - x=[2, 6], - y=[1, 1], - text=["Line positioned relative to the plot", - "Line positioned relative to the axes"], - mode="text", -)) + x=[2, 6], y=[1, 1], mode="text", + text=["Line positioned relative to the plot", "Line positioned relative to the axes"])) # Set axes ranges fig.update_xaxes(range=[0, 8]) @@ -142,36 +109,16 @@ fig.update_yaxes(range=[0, 2]) # Add shapes fig.add_shape( - # Line reference to the axes - go.layout.Shape( - type="line", - xref="x", - yref="y", - x0=4, - y0=0, - x1=8, - y1=1, - line=dict( - color="LightSeaGreen", - width=3, - ), - )) + # Line reference to the axes + type="line", xref="x", yref="y", + x0=4, y0=0, x1=8, y1=1, + line=dict(color="LightSeaGreen", width=3)) + fig.add_shape( - # Line reference to the plot - go.layout.Shape( - type="line", - xref="paper", - yref="paper", - x0=0, - y0=0, - x1=0.5, - y1=0.5, - line=dict( - color="DarkOrange", - width=3, - ), - ), -) + # Line reference to the plot + type="line", xref="paper", yref="paper", + x0=0, y0=0, x1=0.5, y1=0.5, + line=dict(color="DarkOrange",width=3)) fig.show() ``` @@ -180,7 +127,6 @@ fig.show() ```python import plotly.graph_objects as go - import numpy as np # Generate data @@ -189,50 +135,19 @@ y0 = x0 * np.sin(np.power(x0, 2)) + 1 # Create figure with scatter trace fig = go.Figure() +fig.add_trace(go.Scatter(x=x0, y=y0)) -fig.add_trace(go.Scatter( - x=x0, - y=y0, -)) - +# Add tangent line shapes +fig.add_shape(type="line", x0=1, y0=2.30756, x1=1.75, y1=2.30756) +fig.add_shape(type="line", x0=2.5, y0=3.80796, x1=3.05, y1=3.80796) +fig.add_shape(type="line", x0=1.90, y0=-1.1827, x1=2.50, y1=-1.1827) + # Set title text -fig.update_layout( - title_text="$f(x)=x\\sin(x^2)+1\\\\ f\'(x)=\\sin(x^2)+2x^2\\cos(x^2)$" -) +fig.update_layout(title_text="$f(x)=x\\sin(x^2)+1\\\\ f\'(x)=\\sin(x^2)+2x^2\\cos(x^2)$") -# Add tangent line shapes -fig.add_shape( - go.layout.Shape( - type="line", - x0=1, - y0=2.30756, - x1=1.75, - y1=2.30756, - )) -fig.add_shape( - go.layout.Shape( - type="line", - x0=2.5, - y0=3.80796, - x1=3.05, - y1=3.80796, - )) -fig.add_shape( - go.layout.Shape( - type="line", - x0=1.90, - y0=-1.1827, - x1=2.50, - y1=-1.1827, - )) fig.update_shapes(dict( - xref="x", - yref="y", - opacity=0.7, - line=dict( - color="Crimson", - width=2.5, - ))) + xref="x", yref="y", opacity=0.7, line=dict(color="Crimson", width=2.5))) + fig.show() ``` @@ -242,13 +157,11 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - fig.add_trace(go.Scatter( x=[1.5, 4.5], y=[0.75, 0.75], text=["Unfilled Rectangle", "Filled Rectangle"], - mode="text", -)) + mode="text")) # Set axes properties fig.update_xaxes(range=[0, 7], showgrid=False) @@ -256,31 +169,18 @@ fig.update_yaxes(range=[0, 3.5]) # Add shapes fig.add_shape( - # unfilled Rectangle - go.layout.Shape( - type="rect", - x0=1, - y0=1, - x1=2, - y1=3, - line=dict( - color="RoyalBlue", - ), - )) + # unfilled Rectangle + type="rect", + x0=1, y0=1, x1=2, y1=3, + line=dict(color="RoyalBlue")) + fig.add_shape( - # filled Rectangle - go.layout.Shape( - type="rect", - x0=3, - y0=1, - x1=6, - y1=2, - line=dict( - color="RoyalBlue", - width=2, - ), - fillcolor="LightSkyBlue", - )) + # filled Rectangle + type="rect", + x0=3, y0=1, x1=6, y1=2, + line=dict(color="RoyalBlue", width=2), + fillcolor="LightSkyBlue") + fig.update_shapes(dict(xref='x', yref='y')) fig.show() ``` @@ -291,15 +191,12 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Create scatter trace of text labels fig.add_trace(go.Scatter( x=[1.5, 3], y=[2.5, 2.5], - text=["Rectangle reference to the plot", - "Rectangle reference to the axes"], - mode="text", -)) + text=["Rectangle reference to the plot", "Rectangle reference to the axes"], + mode="text")) # Set axes properties fig.update_xaxes(range=[0, 4], showgrid=False) @@ -307,38 +204,20 @@ fig.update_yaxes(range=[0, 4]) # Add shapes fig.add_shape( - # Rectangle reference to the axes - go.layout.Shape( - type="rect", - xref="x", - yref="y", - x0=2.5, - y0=0, - x1=3.5, - y1=2, - line=dict( - color="RoyalBlue", - width=3, - ), - fillcolor="LightSkyBlue", - )) -fig.add_shape( - # Rectangle reference to the plot - go.layout.Shape( - type="rect", - xref="paper", - yref="paper", - x0=0.25, - y0=0, - x1=0.5, - y1=0.5, - line=dict( - color="LightSeaGreen", - width=3, - ), - fillcolor="PaleTurquoise", - )) + # Rectangle reference to the axes + type="rect", + xref="x", yref="y", + x0=2.5, y0=0, x1=3.5, y1=2, + line=dict(color="RoyalBlue", width=3), + fillcolor="LightSkyBlue") +fig.add_shape( + # Rectangle reference to the plot + type="rect", + xref="paper", yref="paper", + x0=0.25, y0=0, x1=0.5, y1=0.5, + line=dict(color="LightSeaGreen", width=3), + fillcolor="PaleTurquoise") fig.show() ``` @@ -348,7 +227,6 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Add scatter trace for line fig.add_trace(go.Scatter( x=["2015-02-01", "2015-02-02", "2015-02-03", "2015-02-04", "2015-02-05", @@ -360,45 +238,34 @@ fig.add_trace(go.Scatter( y=[-14, -17, -8, -4, -7, -10, -12, -14, -12, -7, -11, -7, -18, -14, -14, -16, -13, -7, -8, -14, -8, -3, -9, -9, -4, -13, -9, -6], mode="lines", - name="temperature" -)) + name="temperature")) # Add shape regions fig.update_layout( shapes=[ - # 1st highlight during Feb 4 - Feb 6 - go.layout.Shape( + dict( + # 1st highlight during Feb 4 - Feb 6 type="rect", # x-reference is assigned to the x-values xref="x", # y-reference is assigned to the plot paper [0,1] yref="paper", - x0="2015-02-04", - y0=0, - x1="2015-02-06", - y1=1, + x0="2015-02-04", y0=0, + x1="2015-02-06", y1=1, fillcolor="LightSalmon", opacity=0.5, layer="below", - line_width=0, - ), - # 2nd highlight during Feb 20 - Feb 23 - go.layout.Shape( + line_width=0), + dict( + # 2nd highlight during Feb 20 - Feb 23 type="rect", - xref="x", - yref="paper", - x0="2015-02-20", - y0=0, - x1="2015-02-22", - y1=1, + xref="x", yref="paper", + x0="2015-02-20", y0=0, + x1="2015-02-22", y1=1, fillcolor="LightSalmon", opacity=0.5, layer="below", - line_width=0, - ) - ] -) - + line_width=0)]) fig.show() ``` @@ -408,15 +275,12 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Create scatter trace of text labels fig.add_trace(go.Scatter( x=[1.5, 3.5], y=[0.75, 2.5], - text=["Unfilled Circle", - "Filled Circle"], - mode="text", -)) + text=["Unfilled Circle", "Filled Circle"], + mode="text")) # Set axes properties fig.update_xaxes(range=[0, 4.5], zeroline=False) @@ -425,34 +289,20 @@ fig.update_yaxes(range=[0, 4.5]) # Add circles fig.update_layout( shapes=[ - # unfilled circle - go.layout.Shape( + dict( + # unfilled circle type="circle", - xref="x", - yref="y", - x0=1, - y0=1, - x1=3, - y1=3, - line_color="LightSeaGreen", - ), - # filled circle - go.layout.Shape( + xref="x", yref="y", + x0=1, y0=1, x1=3, y1=3, + line_color="LightSeaGreen"), + dict( + # filled circle type="circle", - xref="x", - yref="y", + xref="x", yref="y", fillcolor="PaleTurquoise", - x0=3, - y0=3, - x1=4, - y1=4, - line_color="LightSeaGreen", - ), - ] -) - -# Set figure size -fig.update_layout(width=800, height=800) + x0=3, y0=3, x1=4, y1=4, + line_color="LightSeaGreen")], + width=800, height=800) fig.show() ``` @@ -461,10 +311,9 @@ fig.show() ```python import plotly.graph_objects as go - import numpy as np -np.random.seed(1) +np.random.seed(1) # Generate data x0 = np.random.normal(2, 0.45, 300) y0 = np.random.normal(2, 0.45, 300) @@ -479,86 +328,47 @@ y2 = np.random.normal(4, 0.3, 200) fig = go.Figure() # Add scatter traces -fig.add_trace(go.Scatter( - x=x0, - y=y0, - mode="markers", -)) - -fig.add_trace(go.Scatter( - x=x1, - y=y1, - mode="markers" -)) - -fig.add_trace(go.Scatter( - x=x2, - y=y2, - mode="markers" -)) - -fig.add_trace(go.Scatter( - x=x1, - y=y0, - mode="markers" -)) +fig.add_trace(go.Scatter(x=x0, y=y0, mode="markers")) +fig.add_trace(go.Scatter(x=x1, y=y1, mode="markers")) +fig.add_trace(go.Scatter(x=x2, y=y2, mode="markers")) +fig.add_trace(go.Scatter(x=x1, y=y0, mode="markers")) # Add shapes fig.update_layout( shapes=[ - go.layout.Shape( + dict( type="circle", - xref="x", - yref="y", - x0=min(x0), - y0=min(y0), - x1=max(x0), - y1=max(y0), + xref="x", yref="y", + x0=min(x0), y0=min(y0), + x1=max(x0), y1=max(y0), opacity=0.2, fillcolor="blue", - line_color="blue", - ), - go.layout.Shape( + line_color="blue"), + dict( type="circle", - xref="x", - yref="y", - x0=min(x1), - y0=min(y1), - x1=max(x1), - y1=max(y1), + xref="x", yref="y", + x0=min(x1), y0=min(y1), + x1=max(x1), y1=max(y1), opacity=0.2, fillcolor="orange", - line_color="orange", - ), - go.layout.Shape( + line_color="orange"), + dict( type="circle", - xref="x", - yref="y", - x0=min(x2), - y0=min(y2), - x1=max(x2), - y1=max(y2), + xref="x", yref="y", + x0=min(x2), y0=min(y2), + x1=max(x2), y1=max(y2), opacity=0.2, fillcolor="green", - line_color="green", - ), - go.layout.Shape( + line_color="green"), + dict( type="circle", - xref="x", - yref="y", - x0=min(x1), - y0=min(y0), - x1=max(x1), - y1=max(y0), + xref="x", yref="y", + x0=min(x1), y0=min(y0), + x1=max(x1), y1=max(y0), opacity=0.2, fillcolor="red", - line_color="red", - ), - ], -) - -# Hide legend -fig.update_layout(showlegend=False) + line_color="red")], + showlegend=False) fig.show() ``` @@ -569,72 +379,35 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Create scatter trace of text labels fig.add_trace(go.Scatter( - x=[1, 1.75, 2.5], - y=[1, 1, 1], - text=["$A$", "$A+B$", "$B$"], - mode="text", - textfont=dict( - color="black", - size=18, - family="Arail", - ) -)) + x=[1, 1.75, 2.5], y=[1, 1, 1], + text=["$A$", "$A+B$", "$B$"], mode="text", + textfont=dict(color="black", size=18, family="Arail"))) # Update axes properties -fig.update_xaxes( - showticklabels=False, - showgrid=False, - zeroline=False, -) - -fig.update_yaxes( - showticklabels=False, - showgrid=False, - zeroline=False, -) +fig.update_xaxes(showticklabels=False, showgrid=False, zeroline=False) +fig.update_yaxes(showticklabels=False, showgrid=False, zeroline=False) # Add circles -fig.add_shape( - go.layout.Shape( +fig.update_layout( + shapes=[ + dict( type="circle", fillcolor="blue", - x0=0, - y0=0, - x1=2, - y1=2, - line_color="blue" - )) -fig.add_shape( - go.layout.Shape( + x0=0, y0=0, x1=2, y1=2, + line_color="blue"), + dict( type="circle", fillcolor="gray", - x0=1.5, - y0=0, - x1=3.5, - y1=2, - line_color="gray" - )) -fig.update_shapes(dict( - opacity=0.3, - xref="x", - yref="y", - layer="below" -)) -# Update figure dimensions -fig.update_layout( - margin=dict( - l=20, - r=20, - b=100 - ), - height=600, + x0=1.5, y0=0, x1=3.5, y1=2, + line_color="gray")], + margin=dict(l=20, r=20, b=100), + height=600, width=800, - plot_bgcolor="white" -) + plot_bgcolor="white") +fig.update_shapes(dict(opacity=0.3, xref="x", yref="y", layer="below")) fig.show() ``` @@ -644,61 +417,42 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - # Create scatter trace of text labels fig.add_trace(go.Scatter( x=[2, 1, 8, 8], y=[0.25, 9, 2, 6], - text=["Filled Triangle", - "Filled Polygon", - "Quadratic Bezier Curves", - "Cubic Bezier Curves"], - mode="text", -)) + text=["Filled Triangle", "Filled Polygon", "Quadratic Bezier Curves", "Cubic Bezier Curves"], + mode="text")) # Update axes properties -fig.update_xaxes( - range=[0, 9], - zeroline=False, -) - -fig.update_yaxes( - range=[0, 11], - zeroline=False, -) +fig.update_xaxes(range=[0, 9], zeroline=False) +fig.update_yaxes(range=[0, 11], zeroline=False) # Add shapes fig.update_layout( shapes=[ # Quadratic Bezier Curves - go.layout.Shape( + dict( type="path", path="M 4,4 Q 6,0 8,4", - line_color="RoyalBlue", - ), + line_color="RoyalBlue"), # Cubic Bezier Curves - go.layout.Shape( + dict( type="path", path="M 1,4 C 2,8 6,4 8,8", - line_color="MediumPurple", - ), + line_color="MediumPurple"), # filled Triangle - go.layout.Shape( + dict( type="path", path=" M 1 1 L 1 3 L 4 1 Z", fillcolor="LightPink", - line_color="Crimson", - ), + line_color="Crimson"), # filled Polygon - go.layout.Shape( + dict( type="path", path=" M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z", fillcolor="PaleTurquoise", - line_color="LightSeaGreen", - ), - ] -) - + line_color="LightSeaGreen")]) fig.show() ``` diff --git a/doc/python/templates.md b/doc/python/templates.md index fbf8e438816..b52d8835fcb 100644 --- a/doc/python/templates.md +++ b/doc/python/templates.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.6 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -23,14 +23,14 @@ jupyter: version: 3.7.3 plotly: description: Theming and templates with plotly with Python - language: python display_as: file_settings + language: python + layout: base name: Theming and templates + order: 7 page_type: u-guide - layout: base permalink: python/templates/ thumbnail: thumbnail/theming-and-templates.png - order: 7 --- ### Theming and templates @@ -180,8 +180,7 @@ symbol_template = go.layout.Template() symbol_template.data.scatter = [ go.Scatter(marker=dict(symbol="diamond", size=10)), go.Scatter(marker=dict(symbol="square", size=10)), - go.Scatter(marker=dict(symbol="circle", size=10)), -] + go.Scatter(marker=dict(symbol="circle", size=10))] fig = go.Figure() fig.update_layout(template=symbol_template) @@ -196,7 +195,7 @@ Note that because we built the template with a list of 3 scatter trace graph obj #### Theming object tuple properties -Some properties in the figure hierarchy are specified as tuples of objects. For example, the text annotations for a graph object figure are stored as a tuple of `go.layout.Annotation` objects in the `annotations` property of the figure's layout. +Some properties in the figure hierarchy are specified as tuples of objects. For example, the text annotations for a graph object figure can be stored as a tuple of `go.layout.Annotation` objects in the `annotations` property of the figure's layout. To use a template to configure the default properties of all of the elements in an object tuple property (e.g. `layout.annotations`), use the `*defaults` property in the template that corresponds to the tuple property (e.g. `layout.template.layout.annotationdefaults`). The `*defaults` template property should be set to a single graph object that matches the type of the elements of the corresponding tuple. The properties of this `*defaults` object in the template will be applied to all elements of the object tuple in the figure that the template is applied to. @@ -206,16 +205,14 @@ Here is an example that creates a template that specifies the default annotation import plotly.graph_objects as go annotation_template = go.layout.Template() -annotation_template.layout.annotationdefaults = go.layout.Annotation(font=dict(color="crimson")) +annotation_template.layout.annotationdefaults = dict(font=dict(color="crimson")) fig = go.Figure() fig.update_layout( template=annotation_template, annotations=[ go.layout.Annotation(text="Look Here", x=1, y=1), - go.layout.Annotation(text="Look There", x=2, y=2) - ] - ) + dict(text="Look There", x=2, y=2)]) fig.show() ``` @@ -232,7 +229,7 @@ import plotly.graph_objects as go draft_template = go.layout.Template() draft_template.layout.annotations = [ - go.layout.Annotation( + dict( name="draft watermark", text="DRAFT", textangle=-30, @@ -242,9 +239,7 @@ draft_template.layout.annotations = [ yref="paper", x=0.5, y=0.5, - showarrow=False, - ) -] + showarrow=False)] fig=go.Figure() fig.update_layout(template=draft_template) @@ -262,7 +257,7 @@ import plotly.graph_objects as go draft_template = go.layout.Template() draft_template.layout.annotations = [ - go.layout.Annotation( + dict( name="draft watermark", text="DRAFT", textangle=-30, @@ -272,20 +267,12 @@ draft_template.layout.annotations = [ yref="paper", x=0.5, y=0.5, - showarrow=False, - ) -] + showarrow=False)] fig = go.Figure() fig.update_layout( template=draft_template, - annotations=[ - go.layout.Annotation( - templateitemname="draft watermark", - text="CONFIDENTIAL", - ) - ] -) + annotations=[dict(templateitemname="draft watermark", text="CONFIDENTIAL")]) fig.show() ``` @@ -301,7 +288,7 @@ import plotly.io as pio pio.templates["draft"] = go.layout.Template( layout_annotations=[ - go.layout.Annotation( + dict( name="draft watermark", text="DRAFT", textangle=-30, @@ -311,10 +298,7 @@ pio.templates["draft"] = go.layout.Template( yref="paper", x=0.5, y=0.5, - showarrow=False, - ) - ] -) + showarrow=False)]) fig = go.Figure() fig.update_layout(template="draft") @@ -331,7 +315,7 @@ import plotly.io as pio pio.templates["draft"] = go.layout.Template( layout_annotations=[ - go.layout.Annotation( + dict( name="draft watermark", text="DRAFT", textangle=-30, @@ -341,12 +325,9 @@ pio.templates["draft"] = go.layout.Template( yref="paper", x=0.5, y=0.5, - showarrow=False, - ) - ] -) -pio.templates.default = "draft" + showarrow=False)]) +pio.templates.default = "draft" fig = go.Figure() fig.show() ``` @@ -364,23 +345,19 @@ import plotly.graph_objects as go import plotly.io as pio pio.templates["draft"] = go.layout.Template( - layout_annotations=[ - go.layout.Annotation( - name="draft watermark", - text="DRAFT", - textangle=-30, - opacity=0.1, - font=dict(color="black", size=100), - xref="paper", - yref="paper", - x=0.5, - y=0.5, - showarrow=False, - ) - ] -) -pio.templates.default = "plotly+draft" + layout_annotations=[dict( + name="draft watermark", + text="DRAFT", + textangle=-30, + opacity=0.1, + font=dict(color="black", size=100), + xref="paper", + yref="paper", + x=0.5, + y=0.5, + showarrow=False)]) +pio.templates.default = "plotly+draft" fig = go.Figure() fig.show() ``` @@ -392,8 +369,7 @@ import plotly.io as pio import plotly.express as px pio.templates["draft"] = go.layout.Template( - layout_annotations=[ - go.layout.Annotation( + layout_annotations=[dict( name="draft watermark", text="DRAFT", textangle=-30, @@ -403,10 +379,8 @@ pio.templates["draft"] = go.layout.Template( yref="paper", x=0.5, y=0.5, - showarrow=False, - ) - ] -) + showarrow=False)]) + pio.templates.default = "plotly+draft" df = px.data.gapminder() @@ -435,7 +409,7 @@ import plotly.io as pio pio.templates["draft"] = go.layout.Template( layout_annotations=[ - go.layout.Annotation( + dict( name="draft watermark", text="DRAFT", textangle=-30, @@ -445,10 +419,7 @@ pio.templates["draft"] = go.layout.Template( yref="paper", x=0.5, y=0.5, - showarrow=False, - ) - ] -) + showarrow=False)]) ``` --- diff --git a/doc/python/ternary-contour.md b/doc/python/ternary-contour.md index 211fc9eb2a0..d3b1b0524d3 100644 --- a/doc/python/ternary-contour.md +++ b/doc/python/ternary-contour.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make Ternary Contour Plots in Python with plotly display_as: scientific diff --git a/doc/python/ternary-plots.md b/doc/python/ternary-plots.md index 195b028b5b1..20165b4746a 100644 --- a/doc/python/ternary-plots.md +++ b/doc/python/ternary-plots.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make Ternary plots in Python with Plotly. display_as: scientific diff --git a/doc/python/ternary-scatter-contour.md b/doc/python/ternary-scatter-contour.md index 417d1860a00..defb54dd4da 100644 --- a/doc/python/ternary-scatter-contour.md +++ b/doc/python/ternary-scatter-contour.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make a scatter plot overlaid on ternary contour in Python with Plotly. diff --git a/doc/python/text-and-annotations.md b/doc/python/text-and-annotations.md index 6e86c1a0500..c36546d5a62 100644 --- a/doc/python/text-and-annotations.md +++ b/doc/python/text-and-annotations.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.2' - jupytext_version: 1.3.0 + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -40,16 +40,9 @@ Here is an example that creates a scatter plot with text labels using Plotly Exp import plotly.express as px df = px.data.gapminder().query("year==2007 and continent=='Americas'") - fig = px.scatter(df, x="gdpPercap", y="lifeExp", text="country", log_x=True, size_max=60) - fig.update_traces(textposition='top center') - -fig.update_layout( - height=800, - title_text='GDP and Life Expectancy (Americas, 2007)' -) - +fig.update_layout(height=800, title_text='GDP and Life Expectancy (Americas, 2007)') fig.show() ``` @@ -59,15 +52,13 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - fig.add_trace(go.Scatter( x=[0, 1, 2], y=[1, 1, 1], mode="lines+markers+text", name="Lines, Markers and Text", text=["Text A", "Text B", "Text C"], - textposition="top center" -)) + textposition="top center")) fig.add_trace(go.Scatter( x=[0, 1, 2], @@ -75,8 +66,7 @@ fig.add_trace(go.Scatter( mode="markers+text", name="Markers and Text", text=["Text D", "Text E", "Text F"], - textposition="bottom center" -)) + textposition="bottom center")) fig.add_trace(go.Scatter( x=[0, 1, 2], @@ -84,8 +74,7 @@ fig.add_trace(go.Scatter( mode="lines+text", name="Lines and Text", text=["Text G", "Text H", "Text I"], - textposition="bottom center" -)) + textposition="bottom center")) fig.show() ``` @@ -133,16 +122,9 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - -fig.add_trace(go.Scatter( - x=[0, 1, 2], - y=[1, 3, 2], - mode="markers", - hovertext=["Text A", "Text B", "Text C"] -)) - +fig.add_trace(go.Scatter(x=[0, 1, 2], y=[1, 3, 2], mode="markers", + hovertext=["Text A", "Text B", "Text C"])) fig.update_layout(title_text="Hover over the points to see the text") - fig.show() ``` @@ -154,34 +136,18 @@ Annotations can be added to a figure using `fig.update_layout(annotations=[...]) import plotly.graph_objects as go fig = go.Figure() - fig.add_trace(go.Scatter( - x=[0, 1, 2, 3, 4, 5, 6, 7, 8], + x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 1, 3, 2, 4, 3, 4, 6, 5] )) - fig.add_trace(go.Scatter( - x=[0, 1, 2, 3, 4, 5, 6, 7, 8], + x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 4, 5, 1, 2, 2, 3, 4, 2] )) - -fig.update_layout( - showlegend=False, - annotations=[ - go.layout.Annotation( - x=2, - y=5, - xref="x", - yref="y", - text="dict Text", - showarrow=True, - arrowhead=7, - ax=0, - ay=-40 - ) - ] -) - +fig.update_layout(showlegend=False) +fig.add_annotation( + x=2, y=5, xref="x", yref="y", text="dict Text", + showarrow=True, arrowhead=7, ax=0, ay=-40) fig.show() ``` @@ -191,41 +157,13 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() +fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 1, 3, 2, 4, 3, 4, 6, 5])) +fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 4, 5, 1, 2, 2, 3, 4, 2])) +fig.add_annotation(dict(x=2, y=5, text="dict Text")) +fig.add_annotation(dict(x=4, y=4, text="dict Text 2")) -fig.add_trace(go.Scatter( - x=[0, 1, 2, 3, 4, 5, 6, 7, 8], - y=[0, 1, 3, 2, 4, 3, 4, 6, 5] -)) - - -fig.add_trace(go.Scatter( - x=[0, 1, 2, 3, 4, 5, 6, 7, 8], - y=[0, 4, 5, 1, 2, 2, 3, 4, 2] -)) - -fig.add_annotation( - go.layout.Annotation( - x=2, - y=5, - text="dict Text") -) -fig.add_annotation( - go.layout.Annotation( - x=4, - y=4, - text="dict Text 2") -) -fig.update_annotations(dict( - xref="x", - yref="y", - showarrow=True, - arrowhead=7, - ax=0, - ay=-40 -)) - +fig.update_annotations(dict(xref="x", yref="y",showarrow=True, arrowhead=7, ax=0, ay=-40)) fig.update_layout(showlegend=False) - fig.show() ``` @@ -235,92 +173,53 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - fig.add_trace(go.Scatter3d( x=["2017-01-01", "2017-02-10", "2017-03-20"], y=["A", "B", "C"], z=[1, 1000, 100000], - name="z", -)) + name="z")) fig.update_layout( - scene=go.layout.Scene( - aspectratio=dict( - x=1, - y=1, - z=1 - ), - camera=dict( - center=dict( - x=0, - y=0, - z=0 - ), - eye=dict( - x=1.96903462608, - y=-1.09022831971, - z=0.405345349304 - ), - up=dict( - x=0, - y=0, - z=1 - ) - ), - dragmode="turntable", - xaxis=dict( - title_text="", - type="date" - ), - yaxis=dict( - title_text="", - type="category" - ), - zaxis=dict( - title_text="", - type="log" - ), - annotations=[dict( - showarrow=False, - x="2017-01-01", - y="A", - z=0, - text="Point 1", - xanchor="left", - xshift=10, - opacity=0.7 - ), dict( - x="2017-02-10", - y="B", - z=4, - text="Point 2", - textangle=0, - ax=0, - ay=-75, - font=dict( - color="black", - size=12 - ), - arrowcolor="black", - arrowsize=3, - arrowwidth=1, - arrowhead=1 - ), dict( - x="2017-03-20", - y="C", - z=5, - ax=50, - ay=0, - text="Point 3", - arrowhead=1, - xanchor="left", - yanchor="bottom" - )] - ), xaxis=dict(title_text="x"), - yaxis=dict(title_text="y") + yaxis=dict(title_text="y")) + +fig.update_scenes( + dict( + aspectratio=dict(x=1, y=1,z=1), + camera=dict(center=dict(x=0, y=0, z=0), + eye=dict(x=1.96903462608, y=-1.09022831971, z=0.405345349304), + up=dict(x=0, y=0, z=1)), + dragmode="turntable", + xaxis=dict(title_text="", type="date"), + yaxis=dict(title_text="", type="category"), + zaxis=dict(title_text="", type="log"), + annotations=[ + dict( + showarrow=False, + x="2017-01-01", y="A", z=0, + text="Point 1", + xanchor="left", + xshift=10, + opacity=0.7), + dict( + x="2017-02-10", y="B", z=4, + text="Point 2", + textangle=0, + ax=0, ay=-75, + font=dict(color="black", size=12), + arrowcolor="black", + arrowsize=3, + arrowwidth=1, + arrowhead=1), + dict( + x="2017-03-20", y="C", z=5, + ax=50, ay=0, + text="Point 3", + arrowhead=1, + xanchor="left", + yanchor="bottom")] + ) ) - fig.show() ``` @@ -330,7 +229,6 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - fig.add_trace(go.Scatter( x=[0, 1, 2], y=[1, 1, 1], @@ -338,12 +236,7 @@ fig.add_trace(go.Scatter( name="Lines, Markers and Text", text=["Text A", "Text B", "Text C"], textposition="top right", - textfont=dict( - family="sans serif", - size=18, - color="crimson" - ) -)) + textfont=dict(family="sans serif", size=18, color="crimson"))) fig.add_trace(go.Scatter( x=[0, 1, 2], @@ -352,15 +245,9 @@ fig.add_trace(go.Scatter( name="Lines and Text", text=["Text G", "Text H", "Text I"], textposition="bottom center", - textfont=dict( - family="sans serif", - size=18, - color="LightSeaGreen" - ) -)) + textfont=dict(family="sans serif", size=18, color="LightSeaGreen"))) fig.update_layout(showlegend=False) - fig.show() ``` @@ -370,30 +257,11 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - -fig.add_trace(go.Scatter( - x=[0, 1, 2, 3, 4, 5, 6, 7, 8], - y=[0, 1, 3, 2, 4, 3, 4, 6, 5] -)) - -fig.add_trace(go.Scatter( - x=[0, 1, 2, 3, 4, 5, 6, 7, 8], - y=[0, 4, 5, 1, 2, 2, 3, 4, 2] -)) - +fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 1, 3, 2, 4, 3, 4, 6, 5])) +fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 4, 5, 1, 2, 2, 3, 4, 2])) fig.add_annotation( - go.layout.Annotation( - x=2, - y=5, - xref="x", - yref="y", - text="max=5", - showarrow=True, - font=dict( - family="Courier New, monospace", - size=16, - color="#ffffff" - ), + x=2, y=5, xref="x", yref="y", text="max=5", showarrow=True, + font=dict(family="Courier New, monospace", size=16, color="#ffffff"), align="center", arrowhead=2, arrowsize=1, @@ -405,9 +273,7 @@ fig.add_annotation( borderwidth=2, borderpad=4, bgcolor="#ff7f0e", - opacity=0.8 - ) -) + opacity=0.8) fig.update_layout(showlegend=False) fig.show() @@ -419,14 +285,7 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - -fig.add_trace(go.Scatter( - x=[1, 2, 3, ], - y=[10, 30, 15], - name="first trace", - hoverinfo="none" -)) - +fig.add_trace(go.Scatter(x=[1, 2, 3, ], y=[10, 30, 15], name="first trace", hoverinfo="none")) fig.show() ``` @@ -439,21 +298,16 @@ fig = go.Figure() fig.add_trace(go.Scattergeo( lat=[45.5, 43.4, 49.13, 51.1, 53.34, 45.24, 44.64, 48.25, 49.89, 50.45], - lon=[-73.57, -79.24, -123.06, -114.1, -113.28, -75.43, -63.57, -123.21, -97.13, - -104.6], + lon=[-73.57, -79.24, -123.06, -114.1, -113.28, -75.43, -63.57, -123.21, -97.13, -104.6], marker={ "color": ["MidnightBlue", "IndianRed", "MediumPurple", "Orange", "Crimson", "LightSeaGreen", "RoyalBlue", "LightSalmon", "DarkOrange", "MediumSlateBlue"], - "line": { - "width": 1 - }, - "size": 10 - }, + "line": {"width": 1}, + "size": 10}, mode="markers+text", name="", text=["Montreal", "Toronto", "Vancouver", "Calgary", "Edmonton", "Ottawa", - "Halifax", - "Victoria", "Winnepeg", "Regina"], + "Halifax", "Victoria", "Winnepeg", "Regina"], textfont={ "color": ["MidnightBlue", "IndianRed", "MediumPurple", "Gold", "Crimson", "LightSeaGreen", @@ -465,22 +319,17 @@ fig.add_trace(go.Scattergeo( "Open Sans, sans-serif", "PT Sans Narrow, sans-serif", "Raleway, sans-serif", "Times New Roman, Times, serif"], - "size": [22, 21, 20, 19, 18, 17, 16, 15, 14, 13] - }, + "size": [22, 21, 20, 19, 18, 17, 16, 15, 14, 13]}, textposition=["top center", "middle left", "top center", "bottom center", - "top right", - "middle left", "bottom right", "bottom left", "top right", - "top right"] -)) + "top right", "middle left", "bottom right", "bottom left", "top right", + "top right"])) fig.update_layout( title_text="Canadian cities", - geo=go.layout.Geo( + geo=dict( lataxis=dict(range=[40, 70]), lonaxis=dict(range=[-130, -55]), - scope="north america" - ) -) + scope="north america")) fig.show() ``` @@ -491,51 +340,37 @@ fig.show() import plotly.graph_objects as go fig = go.Figure() - -fig.add_trace(go.Scatter( - x=[1, 2, 3], - y=[1, 2, 3], - name="y", -)) - +fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name="y")) fig.update_layout( annotations=[ - go.layout.Annotation( + dict( x=0.5, y=-0.15, showarrow=False, text="Custom x-axis title", xref="paper", - yref="paper" - ), - go.layout.Annotation( + yref="paper"), + dict( x=-0.07, y=0.5, showarrow=False, text="Custom y-axis title", textangle=-90, xref="paper", - yref="paper" - ) - ], + yref="paper")], autosize=True, - margin=dict( - b=100 - ), + margin=dict(b=100), title_text="Plot Title", xaxis=dict( autorange=False, range=[-0.05674507980728292, -0.0527310420933204], - type="linear" - ), + type="linear"), yaxis=dict( autorange=False, range=[1.2876210047544652, 1.2977732997811402], - type="linear" - ), + type="linear"), height=550, - width=1137 -) + width=1137) fig.show() ``` @@ -550,10 +385,10 @@ This template string can include `variables` in %{variable} format, `numbers` in import plotly.graph_objects as go fig = go.Figure(go.Pie( - values = [40000000, 20000000, 30000000, 10000000], - labels = ["Wages", "Operating expenses", "Cost of sales", "Insurance"], - texttemplate = "%{label}: %{value:$,s}
(%{percent})", - textposition = "inside")) + values=[40000000, 20000000, 30000000, 10000000], + labels=["Wages", "Operating expenses", "Cost of sales", "Insurance"], + texttemplate="%{label}: %{value:$,s}
(%{percent})", + textposition="inside")) fig.show() ``` @@ -566,15 +401,14 @@ The following example uses [textfont](https://plot.ly/python/reference/#scattert import plotly.graph_objects as go fig = go.Figure(go.Scatterternary( - a = [3, 2, 5], - b = [2, 5, 2], - c = [5, 2, 2], - mode = "markers+text", - text = ["A", "B", "C"], - texttemplate = "%{text}
(%{a:.2f}, %{b:.2f}, %{c:.2f})", - textposition = "bottom center", - textfont = {'family': "Times", 'size': [18, 21, 20], 'color': ["IndianRed", "MediumPurple", "DarkOrange"]} -)) + a=[3, 2, 5], + b=[2, 5, 2], + c=[5, 2, 2], + mode="markers+text", + text=["A", "B", "C"], + texttemplate="%{text}
(%{a:.2f}, %{b:.2f}, %{c:.2f})", + textposition="bottom center", + textfont={'family': "Times", 'size': [18, 21, 20], 'color': ["IndianRed", "MediumPurple", "DarkOrange"]})) fig.show() ``` @@ -590,23 +424,22 @@ from plotly import graph_objects as go fig = go.Figure() fig.add_trace(go.Funnel( - name = 'Montreal', - orientation = "h", - y = ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], - x = [100, 60, 40, 20], - textposition = "inside", - texttemplate = "%{y| %a. %_d %b %Y}")) + name='Montreal', + orientation="h", + y=["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], + x=[100, 60, 40, 20], + textposition="inside", + texttemplate="%{y| %a. %_d %b %Y}")) fig.add_trace(go.Funnel( - name = 'Vancouver', - orientation = "h", - y = ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], - x = [90, 70, 50, 10], - textposition = "inside", - textinfo = "label")) - -fig.update_layout(yaxis = {'type': 'date'}) - + name='Vancouver', + orientation="h", + y=["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], + x=[90, 70, 50, 10], + textposition="inside", + textinfo="label")) + +fig.update_layout(yaxis={'type': 'date'}) fig.show() ``` diff --git a/doc/python/tick-formatting.md b/doc/python/tick-formatting.md index bd9d0221c5d..0903ffffbee 100644 --- a/doc/python/tick-formatting.md +++ b/doc/python/tick-formatting.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.8 + version: 3.7.3 plotly: description: How to format axes ticks in Python with Plotly. display_as: file_settings @@ -44,7 +44,6 @@ fig = go.Figure(go.Scatter( x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], y = [28.8, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9] )) - fig.update_layout( xaxis = dict( tickmode = 'linear', @@ -52,7 +51,6 @@ fig.update_layout( dtick = 0.75 ) ) - fig.show() ``` @@ -64,11 +62,10 @@ If `"array"`, the placement of the ticks is set via `tickvals` and the tick text ```python import plotly.graph_objects as go -go.Figure(go.Scatter( +fig = go.Figure(go.Scatter( x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], y = [28.8, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9] )) - fig.update_layout( xaxis = dict( tickmode = 'array', @@ -76,7 +73,6 @@ fig.update_layout( ticktext = ['One', 'Three', 'Five', 'Seven', 'Nine', 'Eleven'] ) ) - fig.show() ``` @@ -88,13 +84,11 @@ For more formatting types, see: https://github.com/d3/d3-format/blob/master/READ ```python import plotly.graph_objects as go -go.Figure(go.Scatter( +fig = go.Figure(go.Scatter( x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], y = [28.8, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9] )) - fig.update_layout(yaxis_tickformat = '%') - fig.show() ``` @@ -105,20 +99,14 @@ For more date/time formatting types, see: https://github.com/d3/d3-time-format/b ```python import plotly.graph_objects as go - import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv') -fig = go.Figure(go.Scatter( - x = df['Date'], - y = df['AAPL.High'], -)) - +fig = go.Figure(go.Scatter(x = df['Date'], y = df['AAPL.High'])) fig.update_layout( title = 'Time Series with Custom Date-Time Format', - xaxis_tickformat = '%d %B (%a)
%Y' -) + xaxis_tickformat = '%d %B (%a)
%Y') fig.show() ``` @@ -130,16 +118,9 @@ import plotly.graph_objects as go fig = go.Figure(go.Scatter( x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], - y = [68000, 52000, 60000, 20000, 95000, 40000, 60000, 79000, 74000, 42000, 20000, 90000] -)) - -fig.update_layout( - yaxis = dict( - showexponent = 'all', - exponentformat = 'e' - ) -) + y = [68000, 52000, 60000, 20000, 95000, 40000, 60000, 79000, 74000, 42000, 20000, 90000])) +fig.update_layout(yaxis = dict(showexponent = 'all', exponentformat = 'e')) fig.show() ``` @@ -147,16 +128,11 @@ fig.show() ```python import plotly.graph_objects as go - import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv') -fig = go.Figure(go.Scatter( - x = df['Date'], - y = df['mavg'] -)) - +fig = go.Figure(go.Scatter(x = df['Date'], y = df['mavg'])) fig.update_layout( xaxis_tickformatstops = [ dict(dtickrange=[None, 1000], value="%H:%M:%S.%L ms"), @@ -166,9 +142,7 @@ fig.update_layout( dict(dtickrange=[86400000, 604800000], value="%e. %b d"), dict(dtickrange=[604800000, "M1"], value="%e. %b w"), dict(dtickrange=["M1", "M12"], value="%b '%y M"), - dict(dtickrange=["M12", None], value="%Y Y") - ] -) + dict(dtickrange=["M12", None], value="%Y Y")]) fig.show() ``` @@ -178,17 +152,12 @@ fig.show() ```python import plotly.graph_objects as go -fig = go.Figure(go.Bar( - x = ["apples", "oranges", "pears"], - y = [1, 2, 3] -)) - +fig = go.Figure(go.Bar(x = ["apples", "oranges", "pears"], y = [1, 2, 3])) fig.update_xaxes( showgrid=True, ticks="outside", tickson="boundaries", - ticklen=20 -) + ticklen=20) fig.show() ``` diff --git a/doc/python/time-series.md b/doc/python/time-series.md index 0e7d34c50c0..c4430f4e59c 100644 --- a/doc/python/time-series.md +++ b/doc/python/time-series.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to plot date and time in python. display_as: financial