{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plotly Library Basics"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import plotly.graph_objs as go\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('Gapminder-mini.csv', sep=',')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = px.scatter(df, \n",
" x='Income', \n",
" y='Life expectancy',\n",
" color='Region')\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(fig)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = {\n",
" 'data': [{'hovertemplate': 'Region=Europe
Income=%{x}
Life expectancy=%{y}',\n",
" 'legendgroup': 'Europe',\n",
" 'marker': {'color': '#636efa', 'symbol': 'circle'},\n",
" 'mode': 'markers',\n",
" 'name': 'Europe',\n",
" 'orientation': 'v',\n",
" 'showlegend': True,\n",
" 'type': 'scatter',\n",
" 'x': [34735., 35373., 35739., 35816., 36084.],\n",
" 'xaxis': 'x',\n",
" 'y': [82.97, 83.17, 83.33, 83.49, 83.64],\n",
" 'yaxis': 'y'},\n",
" {'hovertemplate': 'Region=Africa
Income=%{x}
Life expectancy=%{y}',\n",
" 'legendgroup': 'Africa',\n",
" 'marker': {'color': '#EF553B', 'symbol': 'circle'},\n",
" 'mode': 'markers',\n",
" 'name': 'Africa',\n",
" 'orientation': 'v',\n",
" 'showlegend': True,\n",
" 'type': 'scatter',\n",
" 'x': [12246., 12233., 12143., 12039., 11986.],\n",
" 'xaxis': 'x',\n",
" 'y': [64.44, 66.31, 66.64, 66.93, 67.19],\n",
" 'yaxis': 'y'}],\n",
" 'layout': {'legend': {'title': {'text': 'Region'}, 'tracegroupgap': 0},\n",
" 'margin': {'t': 60},\n",
" 'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'Income'}},\n",
" 'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'Life expectancy'}}}\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = go.Figure(f)\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = px.scatter(df, \n",
" x='Income', \n",
" y='Life expectancy',\n",
" color='Region',\n",
" animation_frame='Year')\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"print(fig)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}