# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go

import pandas as pd

print(__version__)

# initiate the Plotly Notebook mode  to use plotly.offline and inject the plotly.js source files into the notebook.
init_notebook_mode(connected=True)

#What is plotly https://plot.ly/python/user-guide/#why-graphobjs

# +
#Simple Bar Graph with Plotly

data = [go.Bar(
            x=['oranges', 'apples', 'mangos'],
            y=[10, 20, 30]
    )]

iplot(data, filename='bar')

# +
#Data available from WorldBank or by cloning this repo
#Data Frame

df = pd.read_excel('WorldBankPop2017.xlsx')


#Display the shape i.e the number of rows and columns in the data frame
df.shape

# -

#Check and ensure there are no null values in our data
df.info()

#Check the first 5 rows of the data frame
df.head(5)

# +


#Create a Bar Graph with the 'Country' and 'Population' columns
data = [go.Bar(
            x= df['Country Name'],
            y= df['2017 [YR2017]'],
            width = 0.5
           
    )]

# Add Title to the x and y axis respectively of your plotly graph
layout = go.Layout(
        title='Countrywise Population Distribution',
        xaxis=dict(
        title='Tactics',
        ),
    
  
    yaxis=dict(
        title='Total Population',
        
        
    ),
    
)

#Create and plot the figure with Plotly
fig = go.Figure(data=data, layout=layout)
iplot(fig, filename='basic-bar')

# +
#Its a little hard to see which country has the highest population unless you click on the bars in the plotly graph above
# Lets try to Visualize Data using a Scatter Plot)
#May not be useful see https://python-graph-gallery.com/scatter-plot/

trace = go.Scatter(
    x= df['Country Name'],
    y= df['2017 [YR2017]'],
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook! https://plot.ly/python/line-and-scatter/
iplot(data, filename='basic-scatter')

# +
#https://plot.ly/python/choropleth-maps/#reference


data = [ dict(
        type = 'choropleth',
        locations = df['Country Code'],
        z = df['2017 [YR2017]'],
        text = df['Country Name'],
        showscale = True,
        
      
        marker = dict(
            line = dict (
                color = 'rgb(180,180,180)',
                width = 0.5
            ) ),
        colorbar = dict(
            autotick = False,
            
            title = 'Population'),
      ) ]

layout = dict(
    title = '2017 World Population courtest:\
            <a href="https://databank.worldbank.org/data/reports.aspx?source=2&series=SP.POP.TOTL&country=#">\
            WorldBank</a>',
    geo = dict(
        showframe = False,
        showcoastlines = False,
        projection = dict(
            type = 'Mercator'
        )
    )
)

fig = dict( data=data, layout=layout )
iplot( fig, validate=False, filename='WorldPOP')

# -



StarcoderdataJupyterScriptsDedupFiltered