|
| 1 | +import numpy as np # linear algebra |
| 2 | +import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) |
| 3 | +import matplotlib.pyplot as plt # for plotting the data |
| 4 | +import seaborn as sns # Advanced data plotting on top of matplotlib |
| 5 | +import os |
| 6 | +from pathlib import Path |
| 7 | +import datatable as dt |
| 8 | +import plotly.express as px |
| 9 | + |
| 10 | +%matplotlib inline |
| 11 | +from plotly.offline import init_notebook_mode, iplot |
| 12 | +import plotly.graph_objs as go |
| 13 | +import plotly.offline as py |
| 14 | +py.init_notebook_mode(connected=True) |
| 15 | +from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator, ImageColorGenerator |
| 16 | +%matplotlib inline |
| 17 | + |
| 18 | +f_area = pd.read_csv("../input/global-environmental-indicators/Forests/Forest Area.csv") |
| 19 | + |
| 20 | +f_area = f_area.drop(f_area.index[:1]) |
| 21 | + |
| 22 | +f_area["%change"] = ((f_area["Forest Area, 2020 (1000 ha)"] - f_area["Forest Area, 1990 (1000 ha)"])/ f_area["Forest Area, 1990 (1000 ha)"])*100 |
| 23 | + |
| 24 | +plt.figure(figsize = (20,20)) |
| 25 | +fig = go.Figure(data=go.Choropleth( |
| 26 | + locations=f_area['Country and Area'], # Spatial coordinates |
| 27 | + z = f_area['%change'].astype(float), # Data to be color-coded |
| 28 | + locationmode = 'country names', # set of locations match entries in `locations` |
| 29 | + colorscale = 'RdYlGn', |
| 30 | + colorbar_title = "%change", |
| 31 | + reversescale=True |
| 32 | +)) |
| 33 | +title = '<b>Forest Area % Change</b><br><sup>1990 vs 2020</sup>' |
| 34 | + |
| 35 | +fig.update_layout( |
| 36 | + template="plotly_white", |
| 37 | + title = {'text' : title, |
| 38 | + 'x':0.5, 'xanchor': 'center'}, |
| 39 | + font = {"color" : 'black'} |
| 40 | +) |
| 41 | + |
| 42 | +fig.show() |
0 commit comments