Skip to content

remove go.layout.shape from the tutorial #2104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/python/.mapbox_token
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pk.eyJ1IjoiZXRwaW5hcmQiLCJhIjoiY2luMHIzdHE0MGFxNXVubTRxczZ2YmUxaCJ9.hwWZful0U2CQxit4ItNsiQ
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this file plz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gitignore didn't ignore it! "git rm --cached .mapbox_token" removes it from repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK but it's still here... you'll have to remove it again and push again :)

18 changes: 14 additions & 4 deletions doc/python/animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand Down
116 changes: 49 additions & 67 deletions doc/python/bubble-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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<br>(Click legend to toggle traces)',
showlegend = True,
geo = dict(
scope = 'usa',
landcolor = 'rgb(217, 217, 217)',
)
)
title_text='2014 US city populations<br>(Click legend to toggle traces)',
showlegend=True,
geo=dict(scope='usa', landcolor='rgb(217, 217, 217)'))

fig.show()
```
Expand All @@ -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')
Expand All @@ -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',
Expand All @@ -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'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these trailing parentheses should go back to being on their own line please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping that this PR would be a simple "remove all go.layout.whatever but it actually contains a lot of hard-to-review/hard-to-undo changes like this, so is it possible to please break this up into multiple easier-to-review PRs? like one with just the "go.layout.whatever to dict" change and another with the replacement of = to = etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, to make it less painful I created #2171 for removal of go.layout.* and will take care of formatting later


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<br> \
title = dict(
text='Ebola cases reported by month in West Africa 2014<br> \
Source: <a href="https://data.hdx.rwlabs.org/dataset/rowca-ebola-cases">\
HDX</a>'),
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()
```
Expand Down
48 changes: 18 additions & 30 deletions doc/python/choropleth-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -207,23 +207,21 @@ 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(
locations=df['code'], # Spatial coordinates
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()
```
Expand All @@ -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:
Expand All @@ -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<br>(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()
```
Expand All @@ -285,26 +279,22 @@ fig = go.Figure(data=go.Choropleth(
marker_line_color='darkgray',
marker_line_width=0.5,
colorbar_tickprefix = '$',
colorbar_title = 'GDP<br>Billions US$',
))
colorbar_title = 'GDP<br>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,
xref='paper',
yref='paper',
text='Source: <a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">\
CIA World Factbook</a>',
showarrow = False
)]
)
showarrow = False)])

fig.show()
```
Expand All @@ -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

Expand All @@ -326,22 +315,21 @@ 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,
show_state_data=False,
show_hover=True,
asp = 2.9,
title_text = 'USA by Unemployment %',
legend_title = '% unemployed'
)
legend_title = '% unemployed')

fig.layout.template = None
fig.show()
```
Expand Down
Loading