Skip to content
Snippets Groups Projects
Commit abe055f2 authored by Laura Marcela Becerra's avatar Laura Marcela Becerra
Browse files

delate datos I

parent 45448356
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Conociendo los datos # Conociendo los datos
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%matplotlib widget
import plotly.graph_objs as go
from ipywidgets import interactive, HBox, VBox
import pandas as pd
import numpy as np
#df = pd.read_csv(r'https://nyc3.digitaloceanspaces.com/owid-public/data/co2/owid-co2-data.csv')
df = pd.read_csv('../datos/owid-co2-data.csv')
continents = ['Europe','North America','South America','Asia','Oceania']
co2continents = df[df['country'].isin(continents)]
co2continents = co2continents.rename(columns={"country": "Región"})
```
%% Cell type:code id: tags:
``` python
import plotly.offline as py
from IPython.display import display
fig = go.FigureWidget()
labels = ['Europa','América del Norte','América del Sur','Asia','Oceania']
ymax = co2continents["year"].max()+10
ymin = co2continents["year"].min()-10
i=0
for c in continents:
df = co2continents[co2continents['Región']== c ]
fig.add_scatter( x = df['year'], y = df['co2'] , name=labels[i]#,text="año:"
)
i+=1
fig.update_layout (
xaxis_title="Año",
yaxis_title="co2 [Toneladas]",
autosize=False,
width=800,
height=500,
margin=dict(
l=50,
r=50,
b=50,
t=50,
pad=4),
legend_title="Región",
title = 'Esmisión anual de CO2',
font=dict(
family="Rockwell",
size=16,
#color="RebeccaPurple"
),
plot_bgcolor='rgba(0,0,0,0)'
)
fig.update_xaxes(
ticks='outside',
showline=True,
linecolor='black',
gridcolor='lightgrey',
range=[ymin,ymax]
)
fig.update_yaxes(
ticks='outside',
showline=True,
linecolor='black',
gridcolor='lightgrey'
)
def update_axes(Plot):
i=0
for c in continents:
df = co2continents[co2continents['Región']== c ]
scatter = fig.data[i]
scatter.x = df['year']
scatter.y = df[Plot]
scatter.name=labels[i]
i+=1
if Plot == "co2":
ylabel="co2 [Toneladas]"
else:
ylabel="Porcentaje global"
fig.update_layout (
yaxis_title = ylabel )
axis_dropdowns = interactive(update_axes, Plot = ["co2","share_global_co2"])
mybox = VBox([HBox(axis_dropdowns.children),fig])
display(mybox)
#fig.show()
```
%% Output
%% Cell type:code id: tags:
``` python
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
``` ```
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Conociendo los datos # Conociendo los datos
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%matplotlib widget
import plotly.graph_objs as go
from ipywidgets import interactive, HBox, VBox
import pandas as pd
import numpy as np
#df = pd.read_csv(r'https://nyc3.digitaloceanspaces.com/owid-public/data/co2/owid-co2-data.csv')
df = pd.read_csv('../datos/owid-co2-data.csv')
continents = ['Europe','North America','South America','Asia','Oceania']
co2continents = df[df['country'].isin(continents)]
co2continents = co2continents.rename(columns={"country": "Región"})
```
%% Cell type:code id: tags:
``` python
import plotly.offline as py
from IPython.display import display
fig = go.FigureWidget()
labels = ['Europa','América del Norte','América del Sur','Asia','Oceania']
ymax = co2continents["year"].max()+10
ymin = co2continents["year"].min()-10
i=0
for c in continents:
df = co2continents[co2continents['Región']== c ]
fig.add_scatter( x = df['year'], y = df['co2'] , name=labels[i]#,text="año:"
)
i+=1
fig.update_layout (
xaxis_title="Año",
yaxis_title="co2 [Toneladas]",
autosize=False,
width=800,
height=500,
margin=dict(
l=50,
r=50,
b=50,
t=50,
pad=4),
legend_title="Región",
title = 'Esmisión anual de CO2',
font=dict(
family="Rockwell",
size=16,
#color="RebeccaPurple"
),
plot_bgcolor='rgba(0,0,0,0)'
)
fig.update_xaxes(
ticks='outside',
showline=True,
linecolor='black',
gridcolor='lightgrey',
range=[ymin,ymax]
)
fig.update_yaxes(
ticks='outside',
showline=True,
linecolor='black',
gridcolor='lightgrey'
)
def update_axes(Plot):
i=0
for c in continents:
df = co2continents[co2continents['Región']== c ]
scatter = fig.data[i]
scatter.x = df['year']
scatter.y = df[Plot]
scatter.name=labels[i]
i+=1
if Plot == "co2":
ylabel="co2 [Toneladas]"
else:
ylabel="Porcentaje global"
fig.update_layout (
yaxis_title = ylabel )
axis_dropdowns = interactive(update_axes, Plot = ["co2","share_global_co2"])
mybox = VBox([HBox(axis_dropdowns.children),fig])
display(mybox)
#fig.show()
```
%% Output
%% Cell type:code id: tags:
``` python
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment