-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeo_plot.py
More file actions
59 lines (49 loc) · 1.58 KB
/
geo_plot.py
File metadata and controls
59 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import plotly.graph_objs as go
import pandas as pd
from plotly.offline import init_notebook_mode, iplot, plot
df = pd.read_csv('World Energy Consumption.csv')
data = dict(
type='choropleth',
colorscale='Viridis',
reversescale=True,
locations=df['country'],
locationmode='country names',
z=df['gdp'],
text=df['country'],
colorbar={'title': 'GDP'},
)
layout = dict(
title='GDP',
geo=dict(showframe=False, projection={'type': 'natural earth'})
)
choromap = go.Figure(data=[data], layout=layout)
# Save the plot as an HTML file
plot(choromap, filename='choropleth.html', auto_open=True)
# Bar plot: Coal Production Change Percentage
bar_data = go.Bar(
x=df['country'],
y=df['coal_prod_change_pct'],
name='Coal Production Change Percentage'
)
bar_layout = go.Layout(
title='Coal Production Change Percentage by Country',
xaxis={'title': 'Country'},
yaxis={'title': 'Coal Production Change Percentage'}
)
bar_figure = go.Figure(data=[bar_data], layout=bar_layout)
# Line plot: Oil Production Change Percentage
line_data = go.Scatter(
x=df['country'],
y=df['oil_prod_change_pct'],
mode='lines',
name='Oil Production Change Percentage'
)
line_layout = go.Layout(
title='Oil Production Change Percentage by Country',
xaxis={'title': 'Country'},
yaxis={'title': 'Oil Production Change Percentage'}
)
line_figure = go.Figure(data=[line_data], layout=line_layout)
# Save the plots as HTML files
plot(bar_figure, filename='coal_prod_change.html', auto_open=True)
plot(line_figure, filename='oil_prod_change.html', auto_open=True)