{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"#### Since there are many plotly charts notebook may take some time to load have patience","metadata":{}},{"cell_type":"markdown","source":"#### Plots you are going to be familiar with after this plolty tutorial\n1. Scatter Plot\n2. Line Plot\n3. Bar Plot\n4. Pie Chart\n5. Donut Chart\n6. Area Chart\n7. Color Scales\n8. Sun Burust Charts\n9. Tables & Figure Factory Tables\n10. Bubble Chart\n11. Sankey Diagram","metadata":{}},{"cell_type":"markdown","source":"### Notebook URL for seaborn and matplotlib Tutorial\n\n1. Seaborn Tutorial: https://www.kaggle.com/gaganmaahi224/seaborn-tutorial-17-plots\n2. Matplotlib Tutorial: https://www.kaggle.com/gaganmaahi224/matplotlib-tutorial","metadata":{}},{"cell_type":"code","source":"!pip install dash","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-12-04T04:14:30.260688Z","iopub.execute_input":"2021-12-04T04:14:30.261108Z","iopub.status.idle":"2021-12-04T04:14:51.561614Z","shell.execute_reply.started":"2021-12-04T04:14:30.261005Z","shell.execute_reply":"2021-12-04T04:14:51.560556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go\nimport plotly.offline as po\nfrom plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\nimport matplotlib.pyplot as plt\nimport dash\nimport plotly.express as px\nimport random\nimport plotly.figure_factory as ff\nfrom plotly.offline import iplot","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:51.564141Z","iopub.execute_input":"2021-12-04T04:14:51.564684Z","iopub.status.idle":"2021-12-04T04:14:55.684336Z","shell.execute_reply.started":"2021-12-04T04:14:51.564652Z","shell.execute_reply":"2021-12-04T04:14:55.683475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading Datasets","metadata":{}},{"cell_type":"code","source":"pokemon = pd.read_csv(\"../input/mathplotlib-tutorial/pokemon_updated.csv\")\npokemon.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:55.685592Z","iopub.execute_input":"2021-12-04T04:14:55.685821Z","iopub.status.idle":"2021-12-04T04:14:55.729219Z","shell.execute_reply.started":"2021-12-04T04:14:55.685794Z","shell.execute_reply":"2021-12-04T04:14:55.728414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stdperf = pd.read_csv(\"../input/mathplotlib-tutorial/studentp.csv\")\nstdperf.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:55.731671Z","iopub.execute_input":"2021-12-04T04:14:55.732143Z","iopub.status.idle":"2021-12-04T04:14:55.759442Z","shell.execute_reply.started":"2021-12-04T04:14:55.732100Z","shell.execute_reply":"2021-12-04T04:14:55.758656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corona = pd.read_csv('../input/mathplotlib-tutorial/key-countries-pivoted.csv' ,\n                     index_col='Date' , parse_dates=True)\ncorona.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:55.760894Z","iopub.execute_input":"2021-12-04T04:14:55.761200Z","iopub.status.idle":"2021-12-04T04:14:55.796957Z","shell.execute_reply.started":"2021-12-04T04:14:55.761161Z","shell.execute_reply":"2021-12-04T04:14:55.796268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spotify = pd.read_csv(\"../input/mathplotlib-tutorial/spotify.csv\" ,\n                      index_col=\"Date\")\nspotify.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:55.798251Z","iopub.execute_input":"2021-12-04T04:14:55.798899Z","iopub.status.idle":"2021-12-04T04:14:55.821182Z","shell.execute_reply.started":"2021-12-04T04:14:55.798862Z","shell.execute_reply":"2021-12-04T04:14:55.820220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"housing = pd.read_csv('../input/mathplotlib-tutorial/housing.csv')\nhousing.tail()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:55.822331Z","iopub.execute_input":"2021-12-04T04:14:55.822693Z","iopub.status.idle":"2021-12-04T04:14:55.901003Z","shell.execute_reply.started":"2021-12-04T04:14:55.822661Z","shell.execute_reply":"2021-12-04T04:14:55.900324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"insurance = pd.read_csv('../input/mathplotlib-tutorial/insurance.csv')\ninsurance.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:14:55.902130Z","iopub.execute_input":"2021-12-04T04:14:55.902591Z","iopub.status.idle":"2021-12-04T04:14:55.927798Z","shell.execute_reply.started":"2021-12-04T04:14:55.902550Z","shell.execute_reply":"2021-12-04T04:14:55.927137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install openpyxl","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-12-04T04:14:55.928960Z","iopub.execute_input":"2021-12-04T04:14:55.929534Z","iopub.status.idle":"2021-12-04T04:15:07.092075Z","shell.execute_reply.started":"2021-12-04T04:14:55.929500Z","shell.execute_reply":"2021-12-04T04:15:07.091243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"employment = pd.read_excel(\"../input/mathplotlib-tutorial/unemployment.xlsx\")\nemployment.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.097136Z","iopub.execute_input":"2021-12-04T04:15:07.097400Z","iopub.status.idle":"2021-12-04T04:15:07.529348Z","shell.execute_reply.started":"2021-12-04T04:15:07.097370Z","shell.execute_reply":"2021-12-04T04:15:07.528736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"helpdesk = pd.read_csv(\"../input/mathplotlib-tutorial/helpdesk.csv\")\nhelpdesk.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.530414Z","iopub.execute_input":"2021-12-04T04:15:07.531096Z","iopub.status.idle":"2021-12-04T04:15:07.776278Z","shell.execute_reply.started":"2021-12-04T04:15:07.531061Z","shell.execute_reply":"2021-12-04T04:15:07.775365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fish= pd.read_csv(\"../input/mathplotlib-tutorial/Fish.csv\")\nfish.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.777789Z","iopub.execute_input":"2021-12-04T04:15:07.778096Z","iopub.status.idle":"2021-12-04T04:15:07.804866Z","shell.execute_reply.started":"2021-12-04T04:15:07.778060Z","shell.execute_reply":"2021-12-04T04:15:07.804278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"exercise = pd.read_csv(\"../input/mathplotlib-tutorial/exercise.csv\")\nexercise.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.805946Z","iopub.execute_input":"2021-12-04T04:15:07.806739Z","iopub.status.idle":"2021-12-04T04:15:07.829429Z","shell.execute_reply.started":"2021-12-04T04:15:07.806705Z","shell.execute_reply":"2021-12-04T04:15:07.828770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"suicide = pd.read_csv(\"../input/mathplotlib-tutorial/suicide.csv\") \nsuicide.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.830554Z","iopub.execute_input":"2021-12-04T04:15:07.830824Z","iopub.status.idle":"2021-12-04T04:15:07.942483Z","shell.execute_reply.started":"2021-12-04T04:15:07.830792Z","shell.execute_reply":"2021-12-04T04:15:07.941524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada = pd.read_csv(\"../input/mathplotlib-tutorial/canada.csv\")\ncanada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.944353Z","iopub.execute_input":"2021-12-04T04:15:07.944951Z","iopub.status.idle":"2021-12-04T04:15:07.981538Z","shell.execute_reply.started":"2021-12-04T04:15:07.944902Z","shell.execute_reply":"2021-12-04T04:15:07.980700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.columns","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.983449Z","iopub.execute_input":"2021-12-04T04:15:07.984086Z","iopub.status.idle":"2021-12-04T04:15:07.991866Z","shell.execute_reply.started":"2021-12-04T04:15:07.984015Z","shell.execute_reply":"2021-12-04T04:15:07.990959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.drop(columns=['AREA' , 'DEV', 'DevName' , 'REG', 'Type', 'Coverage' , 'AreaName', 'RegName' ], inplace=True)\ncanada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:07.993442Z","iopub.execute_input":"2021-12-04T04:15:07.994631Z","iopub.status.idle":"2021-12-04T04:15:08.023320Z","shell.execute_reply.started":"2021-12-04T04:15:07.994556Z","shell.execute_reply":"2021-12-04T04:15:08.022137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.rename(columns={'OdName':'Country'} , inplace=True)\ncanada.set_index(canada.Country,inplace=True)\ncanada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.024994Z","iopub.execute_input":"2021-12-04T04:15:08.025354Z","iopub.status.idle":"2021-12-04T04:15:08.053246Z","shell.execute_reply.started":"2021-12-04T04:15:08.025306Z","shell.execute_reply":"2021-12-04T04:15:08.052212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada2 = canada.copy()\ncanada2.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.054816Z","iopub.execute_input":"2021-12-04T04:15:08.055102Z","iopub.status.idle":"2021-12-04T04:15:08.076408Z","shell.execute_reply.started":"2021-12-04T04:15:08.055071Z","shell.execute_reply":"2021-12-04T04:15:08.075449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.index.name=None\ncanada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.077765Z","iopub.execute_input":"2021-12-04T04:15:08.078019Z","iopub.status.idle":"2021-12-04T04:15:08.103894Z","shell.execute_reply.started":"2021-12-04T04:15:08.077990Z","shell.execute_reply":"2021-12-04T04:15:08.103100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del canada['Country']\ncanada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.105001Z","iopub.execute_input":"2021-12-04T04:15:08.105212Z","iopub.status.idle":"2021-12-04T04:15:08.125681Z","shell.execute_reply.started":"2021-12-04T04:15:08.105186Z","shell.execute_reply":"2021-12-04T04:15:08.125028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada = canada.transpose()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.126940Z","iopub.execute_input":"2021-12-04T04:15:08.127798Z","iopub.status.idle":"2021-12-04T04:15:08.138406Z","shell.execute_reply.started":"2021-12-04T04:15:08.127760Z","shell.execute_reply":"2021-12-04T04:15:08.137646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.139373Z","iopub.execute_input":"2021-12-04T04:15:08.140120Z","iopub.status.idle":"2021-12-04T04:15:08.171171Z","shell.execute_reply.started":"2021-12-04T04:15:08.140082Z","shell.execute_reply":"2021-12-04T04:15:08.170545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Scatter Plot","metadata":{}},{"cell_type":"code","source":"#Simple Scatter Plot\nrandom_x = np.random.randint(1,100,50)\nrandom_y = np.random.randint(1,100,50)\n\ndata = [go.Scatter(\n                    x = random_x,\n                    y = random_y,\n                    mode = 'markers'\n                   )\n       ]\nfig = go.Figure(data=data)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:08.172335Z","iopub.execute_input":"2021-12-04T04:15:08.173078Z","iopub.status.idle":"2021-12-04T04:15:09.157666Z","shell.execute_reply.started":"2021-12-04T04:15:08.173032Z","shell.execute_reply":"2021-12-04T04:15:09.156570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Changing Marker size , shape & color using Marker parameter\nx_val = np.random.randint(1,100,50)\ny_val = np.random.randint(1,100,50)\n\ndata = [go.Scatter(\n                    x = x_val,\n                    y = y_val,\n                    mode = 'markers',\n                    marker = dict(\n                                   size = 10, \n                                   color = '#91bd3a', #color of marker\n                                   symbol = 'circle', # Shape of scatter plot\n                                   line = dict(width = 1) #width of boundary\n                                 )\n                   )\n       ]\nfig = go.Figure(data=data)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.159230Z","iopub.execute_input":"2021-12-04T04:15:09.161885Z","iopub.status.idle":"2021-12-04T04:15:09.210062Z","shell.execute_reply.started":"2021-12-04T04:15:09.161827Z","shell.execute_reply":"2021-12-04T04:15:09.209094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Defining Labels (X-Axis & Y-Axis label , Graph tile)\nx_val = np.random.randint(1,100,50)\ny_val = np.random.randint(1,100,50)\n\ndata = [go.Scatter(\n                    x = x_val,\n                    y = y_val,\n                    mode = 'markers',\n                    marker = dict(\n                                  size = 10, \n                                  color = '#4ED700',\n                                  symbol = 'circle',\n                                  line = dict(width = 1,color = '#0E8700')\n                                  )\n                  )\n       ]\nlayout = go.Layout(\n                    title = '$Scatter Plot$', # Title\n                    xaxis = dict(title = '$X-Axis$'), # x-axis label\n                    yaxis = dict(title = '$Y-Axis$'), # y-axis label\n                    )\nfig = go.Figure(data=data, layout=layout)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.211925Z","iopub.execute_input":"2021-12-04T04:15:09.212241Z","iopub.status.idle":"2021-12-04T04:15:09.258130Z","shell.execute_reply.started":"2021-12-04T04:15:09.212195Z","shell.execute_reply":"2021-12-04T04:15:09.257526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_values = np.linspace(0, 100, 100) # 100 evenly spaced values\ny_values = np.random.randn(100)    # 100 random values\n\ntrace0 = go.Scatter(\n                    x = x_values,\n                    y = y_values,\n                    mode = 'markers',\n                    marker = dict(\n                                  size = 7, \n                                  color = '#F4D03F',\n                                  symbol = 'circle',\n                                  line = dict(width = 1,color = '#0E8700')\n                                  )\n                    )\n\ntrace1 = go.Scatter(\n                    x = x_values,\n                    y = y_values-5,\n                    mode = 'markers',\n                    marker = dict(size = 7, \n                                  color = '#A9DFBF',\n                                  symbol = 'circle',\n                                  line = dict(width = 1,color = '#0E8700')\n                                 )\n                    )\n\ndata = [trace0, trace1]  \nfig = go.Figure(data=data)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.259135Z","iopub.execute_input":"2021-12-04T04:15:09.259457Z","iopub.status.idle":"2021-12-04T04:15:09.299794Z","shell.execute_reply.started":"2021-12-04T04:15:09.259429Z","shell.execute_reply":"2021-12-04T04:15:09.298997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"insurance.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.305640Z","iopub.execute_input":"2021-12-04T04:15:09.306137Z","iopub.status.idle":"2021-12-04T04:15:09.321443Z","shell.execute_reply.started":"2021-12-04T04:15:09.306079Z","shell.execute_reply":"2021-12-04T04:15:09.320649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = [go.Scatter(\n                     x = insurance.bmi,\n                     y = insurance.charges,\n                     mode = 'markers',\n                     marker = dict(size = 7, \n                                   color = '#4ED700',\n                                   symbol = 'circle',\n                                   line = dict(width = 1,color = '#0E8700')\n                                  )\n                   )\n       ]\n\nlayout = go.Layout(\n                    title = '$Insurance$', # Chart Title\n                    xaxis = dict(title = '$BMI$'), # x-axis label\n                    yaxis = dict(title = '$Charges$'), # y-axis label\n                   )\n\nfig = go.Figure(data=data, layout=layout)\n\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.322825Z","iopub.execute_input":"2021-12-04T04:15:09.323252Z","iopub.status.idle":"2021-12-04T04:15:09.365379Z","shell.execute_reply.started":"2021-12-04T04:15:09.323218Z","shell.execute_reply":"2021-12-04T04:15:09.364570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = [go.Scatter(\n                     x = insurance.bmi,\n                     y = insurance.charges,\n                     mode = 'markers',\n                     marker = dict(size = 7, \n                                   color = '#4ED700',\n                                   symbol = 'circle',\n                                   line = dict(width = 1,color = '#0E8700')\n                                   )\n                   )\n       ]\n\nlayout = go.Layout(\n                    title = '$Insurance$', # Title\n                    xaxis = dict(title = '$BMI$'), # x-axis label\n                    yaxis = dict(title = '$Charges$'), # y-axis label\n                   )\n\nfig = go.Figure(data=data, layout=layout)\n\n# Updating Traces\nfig.update_traces(\n                  marker=dict(color=\"#e6e56c\"),\n                 )\n\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.366805Z","iopub.execute_input":"2021-12-04T04:15:09.367066Z","iopub.status.idle":"2021-12-04T04:15:09.407999Z","shell.execute_reply.started":"2021-12-04T04:15:09.367031Z","shell.execute_reply":"2021-12-04T04:15:09.407106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# trace0 will capture all smokers\ntrace0 = go.Scatter(\n                      x = insurance[insurance.smoker=='yes'].bmi,\n                      y = insurance[insurance.smoker=='yes'].charges,\n                      mode = 'markers',\n                      name = 'Smoker',\n                    marker = dict(size = 7, color = '#F39C12',symbol = 'circle',line = dict(width = 1))\n                    )\n\n# trace1 will capture all non-smokers\ntrace1 = go.Scatter(\n                     x = insurance[insurance.smoker=='no'].bmi,\n                     y = insurance[insurance.smoker=='no'].charges,\n                     mode = 'markers',\n                     name = 'Non-Smoker',\n                     marker = dict(size = 7, color = '#8BC34A',symbol = 'circle',line = dict(width = 1))\n                    )\n\nlayout = go.Layout(\n                    title = '$Scatter Plot$', # Title\n                    xaxis = dict(title = '$BMI$'), # x-axis label\n                    yaxis = dict(title = '$Charges$'), # y-axis label\n                   )\n\ndata = [trace0, trace1]  \nfig = go.Figure(data=data,layout=layout)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.409821Z","iopub.execute_input":"2021-12-04T04:15:09.410158Z","iopub.status.idle":"2021-12-04T04:15:09.463526Z","shell.execute_reply.started":"2021-12-04T04:15:09.410112Z","shell.execute_reply":"2021-12-04T04:15:09.462562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# trace0 will capture all smokers\ntrace0 = go.Scatter(\n                      x = insurance[insurance.smoker=='yes'].bmi,\n                      y = insurance[insurance.smoker=='yes'].charges,\n                      mode = 'markers',\n                      name = 'Smoker',\n                      marker = dict(size = 14, color = '#9ca4c4',symbol = 'circle',\n                                    line = dict(width = 1,color = '#5D6D7E')\n                                   )\n       \n                    )\n\n# trace1 will capture all non-smokers\ntrace1 = go.Scatter(\n                     x = insurance[insurance.smoker=='no'].bmi,\n                     y = insurance[insurance.smoker=='no'].charges,\n                     mode = 'markers',\n                     name = 'Non-Smoker',\n                     marker = dict(size = 14, color = '#cbcbcb',symbol = 'circle',\n                                   line = dict(width = 1,color = '#626567')\n                                  )\n                    )\n\n#Layout Setting\nlayout = go.Layout(\n                    title=dict(text = \"Insurance Data\",x=0.5,y=0.95),\n                    title_font_size=30,\n                    title_font_color='#F1C40F',\n                    xaxis=dict(\n                               showgrid=False, # Hide Gridlines\n                               showline=True, # Show X-Axis\n                               linecolor='black', # Color of X-axis\n                               tickfont_color='black', #Color of ticks\n                               showticklabels=True, #Show X labels\n                               dtick=5,\n                               ticks='outside',\n                               tickcolor='black',\n                               ),\n    \n                   yaxis=dict(\n                               showgrid=False,\n                               showline=True,\n                               linecolor='black',\n                               tickfont_color='black',\n                               showticklabels=True,\n                               ticks='outside',\n                               tickcolor='black',\n                               ),\n                   legend=dict(\n                                font_size=15,\n                                yanchor='bottom',\n                                xanchor='right',\n                               ),\n                    paper_bgcolor='white',\n                    plot_bgcolor='white',\n                    hovermode='closest',\n                    width=970,\n                    height=800,\n                    )\n\ndata = [trace0, trace1]  \nfig = go.Figure(data=data,layout=layout)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.464944Z","iopub.execute_input":"2021-12-04T04:15:09.465171Z","iopub.status.idle":"2021-12-04T04:15:09.568045Z","shell.execute_reply.started":"2021-12-04T04:15:09.465144Z","shell.execute_reply":"2021-12-04T04:15:09.567103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display multiple Scatter plots in one figure using Subplots\n\nfrom plotly.subplots import make_subplots\n\n#Subplot initialization\nfig = make_subplots(\n                     rows=1, \n                     cols=2,\n                     subplot_titles=(\"Subplot-1\", \"Subplot-2\")\n                   )\n\n\n# Subplot - 1 (Add graph object trace to a figure)\nfig.add_trace(go.Scatter\n                  (\n                    x = x_val,\n                    y = y_val,\n                    mode = 'markers',\n                    marker = dict(size = 10, color = 'crimson',symbol = 'circle',line = dict(width = 1,color = '#0E8700'))\n                  ),\n              row=1, col=1\n             )\n\n# Add graph object trace to a figure (Subplot-2)\nfig.add_trace(go.Scatter\n                  (\n                    x = x_val,\n                    y = y_val,\n                    mode = 'markers',\n                    marker = dict(size = 10, color = 'gold',symbol = 'circle',line = dict(width = 1))\n                   ),\n              row=1, col=2\n             )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.569589Z","iopub.execute_input":"2021-12-04T04:15:09.569939Z","iopub.status.idle":"2021-12-04T04:15:09.722613Z","shell.execute_reply.started":"2021-12-04T04:15:09.569883Z","shell.execute_reply":"2021-12-04T04:15:09.721726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display multiple Scatter plots in one figure using Subplots\n\nfrom plotly.subplots import make_subplots\n\n#Subplot initialization\nfig = make_subplots(\n                     rows=1, \n                     cols=2,\n                     subplot_titles=(\"Subplot-1\", \"Subplot-2\")\n                   )\n\n\n# Subplot - 1 (Add graph object trace to a figure)\nfig.add_trace(go.Scatter\n                  (\n                    x = x_val,\n                    y = y_val,\n                    mode = 'markers',\n                    marker = dict(size = 10, color = '#4ED700',symbol = 'circle',line = dict(width = 1,color = '#0E8700'))\n                  ),\n              row=1, col=1\n             )\n\n# Add graph object trace to a figure\nfig.add_trace(go.Scatter\n                  (\n                    x = x_val,\n                    y = y_val,\n                    mode = 'markers',\n                    marker = dict(size = 10, color = '#FFC107',symbol = 'circle',line = dict(width = 1))\n                   ),\n              row=1, col=2\n             )\n\n#Update traces in Suplots\nfig.update_traces(\n                  marker=dict(color=\"#5DADE2\"),\n                  col=1,\n                  row = 1\n                 )\n\n#Update traces in Suplots\nfig.update_traces(\n                  marker=dict(color=\"#E67E22\"),\n                  col=2,\n                  row = 1\n                 )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.724059Z","iopub.execute_input":"2021-12-04T04:15:09.725038Z","iopub.status.idle":"2021-12-04T04:15:09.769260Z","shell.execute_reply.started":"2021-12-04T04:15:09.724985Z","shell.execute_reply":"2021-12-04T04:15:09.768627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Scatter Plot using Plotly Express","metadata":{}},{"cell_type":"code","source":"xval = np.random.normal(0,10,1000)\nyval = np.random.normal(0,10,1000)\nfig = px.scatter(x=xval,y= yval)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.770489Z","iopub.execute_input":"2021-12-04T04:15:09.771074Z","iopub.status.idle":"2021-12-04T04:15:09.861112Z","shell.execute_reply.started":"2021-12-04T04:15:09.771028Z","shell.execute_reply":"2021-12-04T04:15:09.860287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(\n                  insurance, \n                  x=insurance.bmi,\n                  y= insurance.charges,\n                  color=\"smoker\", # Show groups with different colors using \"color\" parameter\n                  size=insurance.charges\n                )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.862771Z","iopub.execute_input":"2021-12-04T04:15:09.863282Z","iopub.status.idle":"2021-12-04T04:15:09.965312Z","shell.execute_reply.started":"2021-12-04T04:15:09.863239Z","shell.execute_reply":"2021-12-04T04:15:09.964447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(insurance, \n                 x=insurance.bmi,\n                 y= insurance.charges,\n                 color=\"smoker\",  #  Show groups with different colors using \"color\" parameter\n                 size=insurance.charges,\n                 color_discrete_map={\"yes\": \"#FF5722\",\"no\": \"#7CB342\"} #Map colors to data values\n                )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:09.966584Z","iopub.execute_input":"2021-12-04T04:15:09.966856Z","iopub.status.idle":"2021-12-04T04:15:10.047802Z","shell.execute_reply.started":"2021-12-04T04:15:09.966817Z","shell.execute_reply":"2021-12-04T04:15:10.046973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using facet_col arguments to create Sub plots\nfig = px.scatter(insurance, \n                 x=insurance.bmi, \n                 y=insurance.charges, \n                 color=insurance.smoker,   #  Show groups with different colors using \"color\" parameter\n                 facet_col=insurance.region, # Using facet_col arguments to create Sub plots\n                 color_discrete_map={\"yes\": \"#FF5722\",\"no\": \"#7CB342\"}, #Map colors to data values\n                 title=\"Insurance Data\"\n                )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.048965Z","iopub.execute_input":"2021-12-04T04:15:10.049188Z","iopub.status.idle":"2021-12-04T04:15:10.199184Z","shell.execute_reply.started":"2021-12-04T04:15:10.049159Z","shell.execute_reply":"2021-12-04T04:15:10.198355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using facet_row and or facet_col arguments to create Sub plots\nfig = px.scatter(insurance, \n                 x=insurance.bmi, \n                 y=insurance.charges, \n                 color=insurance.smoker, \n                 facet_col=insurance.region, # Using facet_col argument to create Sub plots\n                 facet_row=insurance.sex, # Using facet_row argument to create Sub plots\n                 color_discrete_map={\"yes\": \"#FF5722\",\"no\": \"#7CB342\"},\n                 width=950, \n                 height=800,\n                 title=\"Insurance Data\")\n\nfig.update_layout(\n                    plot_bgcolor= \"#dcedc1\", \n                    paper_bgcolor=\"#FFFDE7\",\n                 )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.200560Z","iopub.execute_input":"2021-12-04T04:15:10.200988Z","iopub.status.idle":"2021-12-04T04:15:10.440702Z","shell.execute_reply.started":"2021-12-04T04:15:10.200930Z","shell.execute_reply":"2021-12-04T04:15:10.440041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using facet_row and or facet_col arguments to create Sub plots\nfig = px.scatter(insurance, \n                 x=insurance.bmi, \n                 y=insurance.charges, \n                 color=insurance.smoker, \n                 facet_col=insurance.region,\n                 facet_row=insurance.sex,\n                 color_discrete_map={\"yes\": \"#FF5722\",\"no\": \"#7CB342\"},\n                 width=950, \n                 height=800,\n                 title=\"Insurance Data\")\n\nfig.update_layout(\n                    plot_bgcolor= \"#dcedc1\",\n                    paper_bgcolor=\"#FFFDE7\",\n                 )\n\n# Updating Traces using \"selector\" argument\nfig.update_traces(\n                  marker_color=\"#339900\",\n                  selector=dict(marker_color=\"#7CB342\")\n                 )\n\n# Updating Traces using \"selector\" argument\nfig.update_traces(\n                  marker_color=\"#FF3333\",\n                  selector=dict(marker_color=\"#FF5722\")\n                 )\n\n\nfig.show()\n#po.plot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.441947Z","iopub.execute_input":"2021-12-04T04:15:10.442334Z","iopub.status.idle":"2021-12-04T04:15:10.702628Z","shell.execute_reply.started":"2021-12-04T04:15:10.442287Z","shell.execute_reply":"2021-12-04T04:15:10.701796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Line Plot","metadata":{}},{"cell_type":"code","source":"#Simple Line Plot\n\nx_values = np.linspace(0, 100, 100) # 100 evenly spaced values\ny_values = np.random.randn(100)   # 100 random values\n\n# create traces\ntrace0 = go.Scatter(\n                    x = x_values,\n                    y = y_values,\n                    mode = 'lines',\n                    )\n \nfig = go.Figure(data=trace0)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.704077Z","iopub.execute_input":"2021-12-04T04:15:10.704329Z","iopub.status.idle":"2021-12-04T04:15:10.717671Z","shell.execute_reply.started":"2021-12-04T04:15:10.704297Z","shell.execute_reply":"2021-12-04T04:15:10.716862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Line Styling\n\nx_values = np.linspace(0, 100, 100) # 100 evenly spaced values\ny_values = np.random.randn(100)   # 100 random values\n\ntrace0 = go.Scatter(\n                    x = x_values,\n                    y = y_values,\n                    mode = 'lines+markers',\n                    )\ntrace1 = go.Scatter(\n                    x = x_values,\n                    y = y_values-5,\n                    mode = 'lines',\n                    )\ndata = [trace0, trace1]  \nfig = go.Figure(data=data)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.719213Z","iopub.execute_input":"2021-12-04T04:15:10.719961Z","iopub.status.idle":"2021-12-04T04:15:10.756927Z","shell.execute_reply.started":"2021-12-04T04:15:10.719915Z","shell.execute_reply":"2021-12-04T04:15:10.756374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.758130Z","iopub.execute_input":"2021-12-04T04:15:10.758505Z","iopub.status.idle":"2021-12-04T04:15:10.776901Z","shell.execute_reply.started":"2021-12-04T04:15:10.758476Z","shell.execute_reply":"2021-12-04T04:15:10.775904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot Immigrants from China\nchina = go.Scatter(\n                    x = canada.index.values,\n                    y = canada['China'],\n                    mode = 'lines',\n                    name = 'China'\n                   )\n\n#Plot Immigrants from India\nindia = go.Scatter(\n                    x = canada.index.values,\n                    y = canada['India'],\n                    mode = 'lines',\n                    name = 'India'\n                  )\n\n#Plot Immigrants from Pakistan\npakistan = go.Scatter(\n                        x = canada.index.values,\n                        y = canada['Pakistan'],\n                        mode = 'lines',\n                        name = 'Pakistan'\n                     )\n\n# Layout setting\nlayout = go.Layout(\n                    title = '$Immigrants$', # Title\n                    xaxis = dict(title = 'Year'), # x-axis label\n                    yaxis = dict(title = 'Number of Immigrants'), # y-axis label\n     \n                  )\n\ndata = [china, india,pakistan]  \nfig = go.Figure(data=data,layout=layout)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.778307Z","iopub.execute_input":"2021-12-04T04:15:10.778682Z","iopub.status.idle":"2021-12-04T04:15:10.822252Z","shell.execute_reply.started":"2021-12-04T04:15:10.778636Z","shell.execute_reply":"2021-12-04T04:15:10.821302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot Immigrants from China\nchina = go.Scatter(\n                    x = canada.index.values,\n                    y = canada['China'],\n                    mode = 'lines',\n                    name = 'China'\n                  )\n\n# Plot Immigrants from India\nindia = go.Scatter(\n                    x = canada.index.values,\n                    y = canada['India'],\n                    mode = 'lines',\n                    name = 'India'\n                  )\n\n# Plot Immigrants from Pakistan\npakistan = go.Scatter(\n                        x = canada.index.values,\n                        y = canada['Pakistan'],\n                        mode = 'lines',\n                        name = 'Pakistan'\n                     )\n\n\nlayout = go.Layout(\n                    title = '$Immigrants$', # Title\n                    xaxis = dict(title = 'Year'), # x-axis label\n                    yaxis = dict(title = 'Number of Immigrants'), # y-axis label\n                    paper_bgcolor= '#FFFDE7' # Paper background color\n     \n                 )\n\ndata = [china, india,pakistan]  \nfig = go.Figure(data=data,layout=layout)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.823966Z","iopub.execute_input":"2021-12-04T04:15:10.824495Z","iopub.status.idle":"2021-12-04T04:15:10.876390Z","shell.execute_reply.started":"2021-12-04T04:15:10.824448Z","shell.execute_reply":"2021-12-04T04:15:10.875547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot Immigrants from China\nchina = go.Scatter(\n                    x = canada.index.values,\n                    y = canada['China'],\n                    mode = 'lines',\n                    name = 'China'\n                  )\n\n# Plot Immigrants from India\nindia = go.Scatter(\n                    x = canada.index.values,\n                    y = canada['India'],\n                    mode = 'lines',\n                    name = 'India'\n                  )\n\n# Plot Immigrants from Pakistan\npakistan = go.Scatter(\n                        x = canada.index.values,\n                        y = canada['Pakistan'],\n                        mode = 'lines',\n                        name = 'Pakistan'\n                     )\n\n\nlayout = go.Layout(\n                    title=dict(text = \"Immigration Data\",x=0.5,y=0.95),\n                    xaxis = dict(title = 'Year'), # x-axis label\n                    yaxis = dict(title = 'Number of Immigrants'), # y-axis label\n                    paper_bgcolor= '#FFFDE7',\n                    plot_bgcolor= '#FFFDE7'\n                  )\n\ndata = [china, india,pakistan]  \nfig = go.Figure(data=data,layout=layout)\niplot(fig)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.877924Z","iopub.execute_input":"2021-12-04T04:15:10.878776Z","iopub.status.idle":"2021-12-04T04:15:10.925730Z","shell.execute_reply.started":"2021-12-04T04:15:10.878730Z","shell.execute_reply":"2021-12-04T04:15:10.924773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada1 = canada.copy()\ndel canada1['Unknown']\ndel canada1['Total']\ncanada1.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.927050Z","iopub.execute_input":"2021-12-04T04:15:10.927332Z","iopub.status.idle":"2021-12-04T04:15:10.958078Z","shell.execute_reply.started":"2021-12-04T04:15:10.927293Z","shell.execute_reply":"2021-12-04T04:15:10.957196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.959375Z","iopub.execute_input":"2021-12-04T04:15:10.959630Z","iopub.status.idle":"2021-12-04T04:15:10.978026Z","shell.execute_reply.started":"2021-12-04T04:15:10.959587Z","shell.execute_reply":"2021-12-04T04:15:10.977328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Immigrants from all countires using for loop\ntraces = [] # Initiate trace\nfor i in canada1.columns:\n    traces.append(\n        go.Scatter(\n                     x=canada1.index.values,\n                     y=canada1[i],\n                     mode='lines',\n                     name = i,\n                     connectgaps=True,\n                   )\n                  ) \n    \nlayout = go.Layout(\n                    title = 'Immigrants', # Title\n                    title_font=dict(size=20),\n                    xaxis = dict(title = 'Year'), # x-axis label\n                    yaxis = dict(title = 'Number of Immigrants'), # y-axis label\n                    font=dict(size=10),\n                    width=1230,\n                    height=650\n                   )\n\nfig = go.Figure(data=traces, layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:10.979430Z","iopub.execute_input":"2021-12-04T04:15:10.979915Z","iopub.status.idle":"2021-12-04T04:15:11.155495Z","shell.execute_reply.started":"2021-12-04T04:15:10.979881Z","shell.execute_reply":"2021-12-04T04:15:11.154659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from plotly.subplots import make_subplots\n\n\n#Subplot initialization\nfig = make_subplots(\n                     rows=1, \n                     cols=2,\n                     subplot_titles=(\"Immigration Data\", \"Insurance Data\")\n                   )\n\n\n# Subplot - 1 (Add graph object trace to a figure)\nfig.add_trace(go.Scatter(\n                         x = canada.index.values,\n                         y = canada['China'],\n                         mode = 'lines',\n                         name = 'China'\n                         ),\n              row=1, col=1\n             )\n\n# Add graph object trace to a figure\nfig.add_trace(go.Scatter(\n                         x = canada.index.values,\n                         y = canada['India'],\n                         mode = 'lines',\n                         name = 'India'\n                        ),\n              row=1, col=1\n             )\n\n# Add graph object trace to a figure\nfig.add_trace(go.Scatter(\n                         x = canada.index.values,\n                         y = canada['Pakistan'],\n                         mode = 'lines',\n                         name = 'Pakistan'\n                        ),\n              row=1, col=1\n             )\n\n\n# Subplot - 2 (Add graph object trace to a figure)\nfig.add_trace(go.Scatter(\n                            x = insurance[insurance.smoker=='yes'].bmi,\n                            y = insurance[insurance.smoker=='yes'].charges,\n                            mode = 'markers',\n                            name = 'Smoker',\n                            marker = dict(size = 7, color = '#F39C12',symbol = 'circle',line = dict(width = 1))\n                        ), \n              row=1, col=2\n             )\n\n# Add graph object trace to a figure\nfig.add_trace(go.Scatter(\n                            x = insurance[insurance.smoker=='no'].bmi,\n                            y = insurance[insurance.smoker=='no'].charges,\n                            mode = 'markers',\n                            name = 'Non-Smoker',\n                            marker = dict(size = 7, color = '#8BC34A',symbol = 'circle',line = dict(width = 1))\n                        ), \n              row=1, col=2\n             )\n\n# Changing X & Y Axis properties\nfig.update_xaxes(title_text=\"Year\", row=1, col=1)\nfig.update_yaxes(title_text=\"Number of Immigrants\", row=1, col=1)\nfig.update_xaxes(title_text=\"BMI\" ,row=1, col=2)\nfig.update_yaxes(title_text=\"Charges\", row=1, col=2)\n\n\n#Changing plot & figure background \nfig.update_layout(\n                    paper_bgcolor= '#FFFDE7',\n                    plot_bgcolor= '#FFFDE7',\n                    title=dict(text = \"Sub Plots\",x=0.5,y=0.95),\n                    title_font_size=30\n                  )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.156895Z","iopub.execute_input":"2021-12-04T04:15:11.157151Z","iopub.status.idle":"2021-12-04T04:15:11.227585Z","shell.execute_reply.started":"2021-12-04T04:15:11.157119Z","shell.execute_reply":"2021-12-04T04:15:11.226628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Line Plot using Plotly Express","metadata":{}},{"cell_type":"code","source":"col1 = np.linspace(0, 10, 1000)\ncol2 = np.sin(col1)\nfig = px.line(\n              x=col1,\n              y= col2,\n              title=\"Sine Plot\"\n             )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.229058Z","iopub.execute_input":"2021-12-04T04:15:11.229826Z","iopub.status.idle":"2021-12-04T04:15:11.311212Z","shell.execute_reply.started":"2021-12-04T04:15:11.229771Z","shell.execute_reply":"2021-12-04T04:15:11.310433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.line(\n              x=col1,\n              y= col2\n             )\nfig.add_scatter(x=col1,\n                y= col2+1\n               )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.312638Z","iopub.execute_input":"2021-12-04T04:15:11.313435Z","iopub.status.idle":"2021-12-04T04:15:11.386522Z","shell.execute_reply.started":"2021-12-04T04:15:11.313386Z","shell.execute_reply":"2021-12-04T04:15:11.385666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot Immigrants from India\nfig = px.line(\n              x=canada1.index.values,\n              y= canada1['India']\n             )\n\n# Plot Immigrants from Pakistan\nfig.add_scatter(\n                 x=canada1.index.values,\n                 y= canada1['Pakistan'], \n                 name = 'Pakistan',\n                 line={'color': 'green'}\n               )\n\n# Plot Immigrants from Bangladesh\nfig.add_scatter(\n                 x=canada1.index.values,\n                 y= canada1['Bangladesh'] , \n                 name = 'Bangladesh', \n                 line={'color': 'red'}\n               )\n\nfig.update_layout(title_text='Immigrants')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.387780Z","iopub.execute_input":"2021-12-04T04:15:11.388038Z","iopub.status.idle":"2021-12-04T04:15:11.465329Z","shell.execute_reply.started":"2021-12-04T04:15:11.387996Z","shell.execute_reply":"2021-12-04T04:15:11.464174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.line(\n              employment, \n              x=\"Period\" , \n              y = \"Unemployed\",\n              color='Gender'\n             )\n\n# Hide grid lines\nfig.update_xaxes(showgrid=False)\nfig.update_yaxes(showgrid=False)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.466895Z","iopub.execute_input":"2021-12-04T04:15:11.467305Z","iopub.status.idle":"2021-12-04T04:15:11.611443Z","shell.execute_reply.started":"2021-12-04T04:15:11.467258Z","shell.execute_reply":"2021-12-04T04:15:11.610344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Bar Plot","metadata":{}},{"cell_type":"code","source":"# Use go.Bar to plot Bar charts in Plotly\nx = np.arange(1,10)\ny = np.arange(20,110,10)\ndata = go.Bar(\n             x= x,\n             y= y,\n             )\n\nlayout = go.Layout(\n                  title = 'Simple Bar Chart'\n                  )\n\n\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.612700Z","iopub.execute_input":"2021-12-04T04:15:11.612923Z","iopub.status.idle":"2021-12-04T04:15:11.628237Z","shell.execute_reply.started":"2021-12-04T04:15:11.612898Z","shell.execute_reply":"2021-12-04T04:15:11.627072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Use go.Bar to plot Bar charts in Plotly\nx1 = [1,2,3,3,3,4,5]\ny1 = [10,20,30,40,50,60,65]\n\n\ndata = go.Bar(\n             x= x1,\n             y= y1,\n             )\n\nlayout = go.Layout(\n                  title = 'Simple Bar Chart'\n                  )\n\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.630154Z","iopub.execute_input":"2021-12-04T04:15:11.630463Z","iopub.status.idle":"2021-12-04T04:15:11.642488Z","shell.execute_reply.started":"2021-12-04T04:15:11.630421Z","shell.execute_reply":"2021-12-04T04:15:11.641923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Changing color of Bar plot\nx = np.arange(1,10)\ny = np.arange(20,130,10)\ndata = go.Bar(\n             x= x,\n             y= y,\n             marker={'color' : '#FFA726'} # changing color of bar plot\n             )\n\nlayout = go.Layout(\n                  title = 'Simple Bar Chart',\n                  width=970,\n                  height=650\n                  )\n\n\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.644051Z","iopub.execute_input":"2021-12-04T04:15:11.645080Z","iopub.status.idle":"2021-12-04T04:15:11.661452Z","shell.execute_reply.started":"2021-12-04T04:15:11.645045Z","shell.execute_reply":"2021-12-04T04:15:11.660677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Changing width of Bar Plot\nx = np.arange(1,10)\ny = np.arange(20,130,10)\nwid = [0.2,]*9\ndata = go.Bar(\n             x= x,\n             y= y,\n             marker={'color' : '#FFA726'}, # Changing color of bars \n             width=wid # Changing width of Bars\n             )\n\nlayout = go.Layout(\n                  title = 'Simple Bar Chart',\n                  width=970,\n                  height=650\n                  )\n\n\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.663171Z","iopub.execute_input":"2021-12-04T04:15:11.663735Z","iopub.status.idle":"2021-12-04T04:15:11.682570Z","shell.execute_reply.started":"2021-12-04T04:15:11.663692Z","shell.execute_reply":"2021-12-04T04:15:11.681692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = np.arange(1,10)\ny = np.arange(20,130,10)\ndata = go.Bar(\n             x= x,\n             y= y,\n             marker_color= '#FFA726', # Changing color of Bars\n             marker_line_color = '#A04000', # Changing color of border\n             marker_line_width = 2, # Changing width of border\n             opacity=0.7 # Changing opacity of Bars\n             )\n\nlayout = go.Layout(\n                  title = 'Simple Bar Chart',\n                  width=970,\n                  height=650\n                  )\n\n\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.684440Z","iopub.execute_input":"2021-12-04T04:15:11.684691Z","iopub.status.idle":"2021-12-04T04:15:11.702165Z","shell.execute_reply.started":"2021-12-04T04:15:11.684663Z","shell.execute_reply":"2021-12-04T04:15:11.701637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Simple Horizontal Bar Plot (Using orientation='h')\nx = np.arange(1,10)\ny = np.arange(20,130,10)\ndata = go.Bar(\n             x= y,\n             y= x,\n             marker={'color' : '#FFA726'},\n             orientation='h'\n             )\n\nlayout = go.Layout(\n                  title = 'Simple Bar Chart',\n                  width=970,\n                  height=650\n                  )\n\n\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.703196Z","iopub.execute_input":"2021-12-04T04:15:11.703972Z","iopub.status.idle":"2021-12-04T04:15:11.718644Z","shell.execute_reply.started":"2021-12-04T04:15:11.703937Z","shell.execute_reply":"2021-12-04T04:15:11.717919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Assignee = ['Asif', 'Basit', 'John', 'Charles','Vignesh', 'Arun', 'Ashish', 'Varun']\nTickets_Closed = np.array([52,42,60,35,48,45,28,54])\nper = (Tickets_Closed/sum(Tickets_Closed))*100\nper = np.round(per, decimals=2)\n\n#Create dataframe\nhelpdesk = pd.DataFrame({'Assignee' : Assignee, 'Tickets Closed' :Tickets_Closed , 'Percentage': per})\nhelpdesk = helpdesk.sort_values(by='Percentage')\n\n#Initialize the figure\nfig = go.Figure()\n\n#Plot Closure percentage using Horizontal Bar plot\nfig.add_trace(go.Bar(\n                     x=helpdesk.Percentage,\n                     y=helpdesk.Assignee,\n                     orientation='h',\n                     marker=dict(\n                                  color='rgba(70, 171, 100, 0.6)',\n                                  line=dict(color='rgba(70, 171, 100, 1.0)',width=1),\n                                 ),\n                     )\n             )\n\n#Update layout\nfig.update_layout(\n                   title=dict(text = \"Ticket Closure Summary\",x=0.46,y=0.95,font_size=20),\n                   yaxis=dict(\n                              showticklabels=True,\n                              ),\n\n                   xaxis=dict(\n                                showticklabels=False,\n                                domain=[0, 0.6],\n                             ),\n                   margin=dict(l=300, r=20, t=70, b=70),\n                   paper_bgcolor='rgb(248, 248, 255)',\n                   plot_bgcolor='rgb(248, 248, 255)',\n                  )\n\n\n\nannotations = [] #Initialize anotation object\n\n\n# Labels\nfor perc, asg in zip(helpdesk.Percentage, helpdesk.Assignee):\n    \n    # Displaying label bar percentage\n    annotations.append(dict(xref='x', \n                            yref='y',\n                            y=asg, \n                            x=perc + 2,\n                            text=str(perc) + '%',\n                            font=dict(family='Arial', size=12,color='#004D40'),\n                            showarrow=False))\n   # Displaying Footer\n    annotations.append(dict(xref='paper', \n                            yref='paper',\n                            x=1, \n                            y=-0.17,\n                            text='Help Desk ' +'Closure Statistics, ' +'Year 2020',\n                            font=dict(family='Arial', size=11, color='#9E9E9E'),\n                            showarrow=False\n                           )\n                       )\n\nfig.update_layout(annotations=annotations)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.720292Z","iopub.execute_input":"2021-12-04T04:15:11.720796Z","iopub.status.idle":"2021-12-04T04:15:11.765578Z","shell.execute_reply.started":"2021-12-04T04:15:11.720759Z","shell.execute_reply":"2021-12-04T04:15:11.764980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x1= [1,3,5,7] \nx2=[2,4,6,8]\ny1 = [7,7,7,7]\ny2= [17,18,29,40]\n\ntrace0 = go.Bar(\n             x= x1,\n             y= y1,\n             marker= dict (color ='#FFA726' )\n             \n             )\n\ntrace1 = go.Bar(\n             x= x2,\n             y= y2,\n             marker={'color' : '#94E413'}\n             )\n\n\ndata = [trace0,trace1]\nfig = go.Figure(data=data)\nfig.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.766581Z","iopub.execute_input":"2021-12-04T04:15:11.767018Z","iopub.status.idle":"2021-12-04T04:15:11.780011Z","shell.execute_reply.started":"2021-12-04T04:15:11.766986Z","shell.execute_reply":"2021-12-04T04:15:11.779324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Stacked Vertical Bar","metadata":{}},{"cell_type":"code","source":"x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\ntrace0 = go.Bar(\n             x= x,\n             y= y1,\n             marker= dict (color ='#FF6F00' ),\n             name = 'Open Tickets'\n             \n             )\n\ntrace1 = go.Bar(\n             x= x,\n             y= y2,\n             marker={'color' : '#FFB300'},\n              name = 'Closed Tickets'\n              )    \n\ntrace2 = go.Bar(\n             x= x,\n             y= y3,\n             marker={'color' : '#F7DC6F'},\n              name = 'Cancelled Tickets'\n              )  \n    \nlayout = go.Layout(\n                   title= 'Open Tickets by Status' , \n                   barmode = 'stack',\n                   width=900,\n                   height=800\n                  )\n\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.781188Z","iopub.execute_input":"2021-12-04T04:15:11.781811Z","iopub.status.idle":"2021-12-04T04:15:11.805660Z","shell.execute_reply.started":"2021-12-04T04:15:11.781778Z","shell.execute_reply":"2021-12-04T04:15:11.804951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Displaying values in bar plot using \"text\" and \"textposition\" parameter\nx = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\ntrace0 = go.Bar(\n             x= x,\n             y= y1,\n             marker= dict (color ='#FF6F00' ),\n             name = 'Open Tickets',\n             text=y1,\n             textposition='auto'             \n             )\n\ntrace1 = go.Bar(\n             x= x,\n             y= y2,\n             marker={'color' : '#FFB300'},\n             name = 'Closed Tickets',\n             text=y2,\n             textposition='auto'     \n              )    \n\ntrace2 = go.Bar(\n             x= x,\n             y= y3,\n             marker={'color' : '#F7DC6F'},\n             name = 'Cancelled Tickets',\n             text=y3,\n             textposition='auto'     \n              )  \n    \nlayout = go.Layout(\n                   title= 'Open Tickets by Status' , \n                   barmode = 'stack',\n                   width=900,\n                   height=800\n                  )\n\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.806822Z","iopub.execute_input":"2021-12-04T04:15:11.807446Z","iopub.status.idle":"2021-12-04T04:15:11.830435Z","shell.execute_reply.started":"2021-12-04T04:15:11.807414Z","shell.execute_reply":"2021-12-04T04:15:11.829542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Stacked Horizontal Bar","metadata":{}},{"cell_type":"code","source":"x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\n\ntrace0 = go.Bar(\n             x= y1,\n             y= x,\n             marker= dict (color ='#FF6F00'),\n             name = 'Open Tickets',\n             orientation='h',\n             text=y1,\n             textposition='auto'           \n             )\n\ntrace1 = go.Bar(\n             x= y2,\n             y= x,\n             marker={'color' : '#FFB300'},\n             name = 'Closed Tickets',\n             orientation='h',\n             text=y2,\n             textposition='auto'  \n              )    \n\n\ntrace2 = go.Bar(\n             x= y3,\n             y= x,\n             marker={'color' : '#F7DC6F'},\n             name = 'Cancelled Tickets',\n             orientation='h',\n             text=y3,\n             textposition='auto'  \n              )  \n    \nlayout = go.Layout(\n                   title= 'Open Tickets by Status' , \n                   barmode = 'stack',\n                   width=990,\n                   height=550\n                  )\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.831985Z","iopub.execute_input":"2021-12-04T04:15:11.832348Z","iopub.status.idle":"2021-12-04T04:15:11.852021Z","shell.execute_reply.started":"2021-12-04T04:15:11.832305Z","shell.execute_reply":"2021-12-04T04:15:11.851429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\n\ntrace0 = go.Bar(\n             x= y1,\n             y= x,\n             marker= dict (color ='#FF9800',line=dict(color='#F4511E',width=2)),\n             name = 'Open Tickets',\n             orientation='h',\n             text=y1,\n             textposition='auto',\n             opacity=0.8,\n             )\n\ntrace1 = go.Bar(\n             x= y2,\n             y= x,\n             marker= dict (color ='#7CB342',line=dict(color='#2E7D32', width=2)),\n             name = 'Closed Tickets',\n             orientation='h',\n             text=y2,\n             textposition='auto',\n             opacity=0.8,   \n              )    \n\n\ntrace2 = go.Bar(\n             x= y3,\n             y= x,\n             marker= dict (color ='#1E88E5',line=dict(color='#3F51B5', width=2)),\n             name = 'Cancelled Tickets',\n             orientation='h',\n             text=y3,\n             textposition='auto',\n             opacity=0.7,   \n              )  \n    \nlayout = go.Layout(\n                   title= 'Open Tickets by Status' , \n                   barmode = 'stack',\n                   width=990,\n                   height=600\n                  )\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.853084Z","iopub.execute_input":"2021-12-04T04:15:11.853669Z","iopub.status.idle":"2021-12-04T04:15:11.874382Z","shell.execute_reply.started":"2021-12-04T04:15:11.853636Z","shell.execute_reply":"2021-12-04T04:15:11.873536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Grouped Bar Chart","metadata":{}},{"cell_type":"code","source":"x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\ntrace0 = go.Bar(\n             x= x,\n             y= y1,\n             marker= dict (color ='#FF6F00' ),\n             name = 'Open Tickets',\n             )\n\ntrace1 = go.Bar(\n             x= x,\n             y= y2,\n             marker={'color' : '#FFB300'},\n              name = 'Closed Tickets'\n              )    \n\ntrace2 = go.Bar(\n             x= x,\n             y= y3,\n             marker={'color' : '#F7DC6F'},\n              name = 'Cancelled Tickets'\n              )  \n    \nlayout = go.Layout(\n                   title= 'Open Tickets by Status' , \n                   width=980,\n                   height=800\n                  )\n\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.875826Z","iopub.execute_input":"2021-12-04T04:15:11.876425Z","iopub.status.idle":"2021-12-04T04:15:11.895499Z","shell.execute_reply.started":"2021-12-04T04:15:11.876383Z","shell.execute_reply":"2021-12-04T04:15:11.894633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Grouped Bar Chart with values displayed outside the bar (Using  textposition='outside')\nx = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\ntrace0 = go.Bar(\n             x= x,\n             y= y1,\n             marker= dict (color ='#FF6F00' ),\n             name = 'Open Tickets',\n             text=y1,\n             textposition='outside'\n             )\n\ntrace1 = go.Bar(\n             x= x,\n             y= y2,\n             marker={'color' : '#FFB300'},\n             name = 'Closed Tickets',\n             text=y2,\n             textposition='outside'\n              )    \n\ntrace2 = go.Bar(\n             x= x,\n             y= y3,\n             marker={'color' : '#F7DC6F'},\n             name = 'Cancelled Tickets',\n             text=y3,\n             textposition='outside'\n              )  \n    \nlayout = go.Layout(\n                   title= 'Open Tickets by Status' , \n                   barmode = 'group',\n                   width=900,\n                   height=800,\n                   xaxis_tickangle=-45\n                  )\n\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.896934Z","iopub.execute_input":"2021-12-04T04:15:11.897296Z","iopub.status.idle":"2021-12-04T04:15:11.921278Z","shell.execute_reply.started":"2021-12-04T04:15:11.897263Z","shell.execute_reply":"2021-12-04T04:15:11.920675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Grouped Bar Chart with values displayed inside the bar using \"auto\" textposition \nx = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \ny1 = [17,18,29,33,38,39,42]\ny2 = [20,21,22,23,21,28,25]\ny3 = [5,13,11,12,13,11,16]\ntrace0 = go.Bar(\n             x= x,\n             y= y1,\n             marker= dict (color ='#FF6F00' ),\n             name = 'Open Tickets',\n             text=y1,\n             textposition='auto'\n             )\n\ntrace1 = go.Bar(\n             x= x,\n             y= y2,\n             marker={'color' : '#FFB300'},\n             name = 'Closed Tickets',\n             text=y2,\n             textposition='auto'\n              )    \n\ntrace2 = go.Bar(\n             x= x,\n             y= y3,\n             marker={'color' : '#F7DC6F'},\n             name = 'Cancelled Tickets',\n             text=y3,\n             textposition='auto'\n              )  \n    \n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Status\",x=0.5,y=0.95,font_size=25), \n                   barmode = 'group',\n                   width=980,\n                   height=800,\n                   xaxis_tickangle=-45,\n                   xaxis_tickfont_size=14,\n                   yaxis=dict(\n                               title='Number of Tickets',\n                               titlefont_size=16,\n                               tickfont_size=14,\n                              ),\n   \n                   xaxis=dict(\n                               title='Assignee',\n                               titlefont_size=16,\n                               tickfont_size=14,\n                              ), \n                  legend=dict(\n                               x=0,\n                               y=1,\n                               bgcolor='rgba(255, 255, 255, 0)',\n                               bordercolor='rgba(255, 255, 255, 0)'\n                              ),\n                  bargap=0.15, # gap between bars of adjacent location coordinates.\n                  bargroupgap=0.08 # gap between bars of the same location coordinate.\n                 )\n\n\ndata = [trace0,trace1,trace2]\nfig = go.Figure(data=data, layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.922800Z","iopub.execute_input":"2021-12-04T04:15:11.923209Z","iopub.status.idle":"2021-12-04T04:15:11.974527Z","shell.execute_reply.started":"2021-12-04T04:15:11.923178Z","shell.execute_reply":"2021-12-04T04:15:11.973810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Bar Plot using Plotly Express","metadata":{}},{"cell_type":"code","source":"#Simple Bar plot using px.bar\n\nx = np.arange(1,10)\ny = np.arange(20,110,10)\nfig = px.bar(x=x, y=y)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:11.975737Z","iopub.execute_input":"2021-12-04T04:15:11.976427Z","iopub.status.idle":"2021-12-04T04:15:12.053846Z","shell.execute_reply.started":"2021-12-04T04:15:11.976387Z","shell.execute_reply":"2021-12-04T04:15:12.053110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = np.arange(1,10)\ny = np.arange(20,110,10)\nfig = px.bar(x=x, y=y,color=y)\nfig.layout.title.text = \"Bar Plot - Plotly Express\"\nfig.update_traces(textposition='outside')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.055002Z","iopub.execute_input":"2021-12-04T04:15:12.055721Z","iopub.status.idle":"2021-12-04T04:15:12.141217Z","shell.execute_reply.started":"2021-12-04T04:15:12.055681Z","shell.execute_reply":"2021-12-04T04:15:12.140352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = np.arange(1,10)\ny = np.arange(20,110,10)\nfig = px.bar(x=x, y=y,color=y,text=y)\nfig.layout.title.text = \"Bar Plot - Plotly Express\"\nfig.update_traces(textposition='outside')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.142709Z","iopub.execute_input":"2021-12-04T04:15:12.143201Z","iopub.status.idle":"2021-12-04T04:15:12.216859Z","shell.execute_reply.started":"2021-12-04T04:15:12.143165Z","shell.execute_reply":"2021-12-04T04:15:12.216223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 100% Stacked Bar Chart","metadata":{}},{"cell_type":"code","source":"col1 = ['Strongly Agree' , 'Agree' , 'Neutral' , 'Disagree' , 'Strongly Disagree',]\nindex1 = ['Python' , 'Java' , 'Julia' , 'C++' , 'C']\nreview = np.array([[428, 111, 70, 101, 80],\n                   [370, 222, 80, 104, 70],\n                   [298, 121, 90, 102, 60],\n                   [310, 141, 100, 109, 56],\n                   [400, 121, 110, 107, 78]]\n                 )\n\nrating = pd.DataFrame(data=review,index=index1,columns=col1)\nrating","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.218006Z","iopub.execute_input":"2021-12-04T04:15:12.218795Z","iopub.status.idle":"2021-12-04T04:15:12.232428Z","shell.execute_reply.started":"2021-12-04T04:15:12.218756Z","shell.execute_reply":"2021-12-04T04:15:12.231764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rating['Total'] = rating.sum(axis=1)\nrating","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.233549Z","iopub.execute_input":"2021-12-04T04:15:12.234160Z","iopub.status.idle":"2021-12-04T04:15:12.258925Z","shell.execute_reply.started":"2021-12-04T04:15:12.234128Z","shell.execute_reply":"2021-12-04T04:15:12.257875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rating = rating.assign(**{'Strongly Agree (%)': np.nan, \n             'Agree (%)' : np.nan, \n             'Neutral (%)': np.nan ,\n             'Disagree (%)' : np.nan, \n             'Strongly Disagree (%)': np.nan,\n            })\nrating","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.260732Z","iopub.execute_input":"2021-12-04T04:15:12.261112Z","iopub.status.idle":"2021-12-04T04:15:12.282477Z","shell.execute_reply.started":"2021-12-04T04:15:12.261062Z","shell.execute_reply":"2021-12-04T04:15:12.281642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(0,len(rating['Strongly Agree'])):\n    k=0\n    for j in range(int(len(rating.iloc[0])/2)+1 , len(rating.iloc[0])):\n        rating.iat[i,j] =  np.round((rating.iat[i,k] / rating.iat[i,5])*100 ,decimals=2)\n        k=k+1\nrating","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.283797Z","iopub.execute_input":"2021-12-04T04:15:12.284202Z","iopub.status.idle":"2021-12-04T04:15:12.313251Z","shell.execute_reply.started":"2021-12-04T04:15:12.284167Z","shell.execute_reply":"2021-12-04T04:15:12.312389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure()\n\n# Trace to plot \"Strongly Agree\" percentage\nfig.add_trace(\n               go.Bar(\n                       x= rating['Strongly Agree (%)'],\n                       y= rating.index,\n                       marker= dict (color ='#2E7D32',line=dict(color='#2E7D32',width=2)),\n                       name = 'Strongly Agree (%)',\n                       orientation='h',\n                       textposition='auto',\n                      )\n             )\n\n\n# Trace to plot \"Agree\" percentage\nfig.add_trace(\n               go.Bar(\n                       x= rating['Agree (%)'],\n                       y= rating.index,\n                       marker= dict (color ='#8BC34A',line=dict(color='#8BC34A',width=2)),\n                       name = 'Agree (%)',\n                       orientation='h',\n                       textposition='auto',\n                      )\n             )\n\n\n\n# Trace to plot \"Neutral\" percentage\nfig.add_trace(\n               go.Bar(\n                       x= rating['Neutral (%)'],\n                       y= rating.index,\n                       marker= dict (color ='#D4E157',line=dict(color='#D4E157',width=2)),\n                       name = 'Neutral (%)',\n                       orientation='h',\n                       textposition='auto',\n                      )\n             )\n\n\n\n# Trace to plot \"Disagree\" percentage\nfig.add_trace(\n               go.Bar(\n                       x= rating['Disagree (%)'],\n                       y= rating.index,\n                       marker= dict (color ='#FFB300',line=dict(color='#FFB300',width=2)),\n                       name = 'Disagree (%)',\n                       orientation='h',\n                       textposition='auto',\n                      )\n             )\n\n\n\n\n# Trace to plot \"Strongly Disagree\" percentage\nfig.add_trace(\n               go.Bar(\n                       x= rating['Strongly Disagree (%)'],\n                       y= rating.index,\n                       marker= dict (color ='#FF7043',line=dict(color='#FF7043',width=2)),\n                       name = 'Strongly Disagree (%)',\n                       orientation='h',\n                       textposition='auto',\n                      )\n             )\n\n\n# Layout setting\nfig.update_layout(\n                   title=dict(text = \"Best Programming Language\",x=0.44,y=0.95,font_size=20), \n                   barmode = 'stack',\n                   width=1000,\n                   height=500,\n                   margin=dict(l=70, r=0, t=70, b=70),\n                   paper_bgcolor='rgb(248, 248, 255)',\n                   plot_bgcolor='rgb(248, 248, 255)',\n                  )\n\nannotations =[]\n\n\n\n# Displaying bar percentage label for \"Strongly Agree\"\nfor perc, lang in zip(rating.iloc[:,6],rating.index):\n    # labeling the bar percentage\n    annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 , \n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='white'),\n                            showarrow=False))\n\n\n# Displaying bar percentage label for \"Agree\"\ni=0\nfor perc, lang in zip(rating.iloc[:,7],rating.index):\n    # labeling the bar percentage\n    annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 + rating.iloc[i,6],\n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='white'),\n                            showarrow=False))\n    i+=1\n\n\n# Displaying bar percentage label for \"Neutral\"\ni=0\nfor perc, lang in zip(rating.iloc[:,8],rating.index):\n    # labeling the bar percentage\n    annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 + rating.iloc[i,6]+rating.iloc[i,7],\n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='black'),\n                            showarrow=False))\n    i+=1\n    \n    \n\n# Displaying bar percentage label for \"Disagree\"\ni=0\nfor perc, lang in zip(rating.iloc[:,9],rating.index):\n    # labeling the bar percentage\n    annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 + rating.iloc[i,6]+rating.iloc[i,7]+rating.iloc[i,8],\n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='black'),\n                            showarrow=False))\n    i+=1\n\n    \n    \n# Displaying bar percentage label for \"Strongly Disagree\"\ni=0\nfor perc, lang in zip(rating.iloc[:,10],rating.index):\n    # labeling the bar percentage\n    annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 + rating.iloc[i,6]+rating.iloc[i,7]+rating.iloc[i,8] + rating.iloc[i,9],\n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='black'),\n                            showarrow=False))\n    i+=1\n\nfig.update_layout(annotations=annotations)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.315174Z","iopub.execute_input":"2021-12-04T04:15:12.315695Z","iopub.status.idle":"2021-12-04T04:15:12.378363Z","shell.execute_reply.started":"2021-12-04T04:15:12.315649Z","shell.execute_reply":"2021-12-04T04:15:12.377347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Optimized code for above visualization\nfig = go.Figure()\ncols = ['#2E7D32' , '#8BC34A' , '#D4E157' , '#FFB300' , '#FF7043']\n\nfor i in range (0,5):\n    fig.add_trace(\n               go.Bar(\n                       x= rating.iloc[:,6+i],\n                       y= rating.index,\n                       marker= dict (color =cols[i],line=dict(color=cols[i],width=2)),\n                       name = 'Strongly Agree (%)',\n                       orientation='h',\n                       textposition='auto',\n                      )\n                 )\n\nfig.update_layout(\n                   title=dict(text = \"Best Programming Language\",x=0.44,y=0.95,font_size=20), \n                   barmode = 'stack',\n                   width=1000,\n                   height=500,\n                   margin=dict(l=70, r=0, t=70, b=70),\n                   paper_bgcolor='rgb(248, 248, 255)',\n                   plot_bgcolor='rgb(248, 248, 255)',\n                  )\n\nannotations =[]\n\n\ni=0   \nfor j in range(1,6):\n    if j==1:\n        for perc, lang in zip(rating.iloc[:,5+j],rating.index):\n            # labeling the bar percentage\n            annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 , \n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='white'),\n                            showarrow=False))\n        sum1 = rating.iloc[:,5+j]\n    \n    \n    else:\n        i=0\n        for perc, lang in zip(rating.iloc[:,5+j],rating.index):\n            # labeling the bar percentage\n            annotations.append(dict(xref='x', \n                            yref='y',\n                            y=lang, \n                            x=perc/2 + sum1[i],\n                            text=str(perc) + ' %',\n                            font=dict(family='Arial', size=12,color='black'),\n                            showarrow=False))\n            i+=1\n        sum1 = sum1+ rating.iloc[:,5+j]\n\nfig.update_layout(annotations=annotations)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.380298Z","iopub.execute_input":"2021-12-04T04:15:12.380646Z","iopub.status.idle":"2021-12-04T04:15:12.430338Z","shell.execute_reply.started":"2021-12-04T04:15:12.380587Z","shell.execute_reply":"2021-12-04T04:15:12.429571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Pie & Donut Chart","metadata":{}},{"cell_type":"code","source":"#Simple Pie Chart\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ndata = go.Pie(\n             values= tickets,\n             labels= status,\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20)\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.431478Z","iopub.execute_input":"2021-12-04T04:15:12.432306Z","iopub.status.idle":"2021-12-04T04:15:12.449069Z","shell.execute_reply.started":"2021-12-04T04:15:12.432270Z","shell.execute_reply":"2021-12-04T04:15:12.448412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Changing color of Pie Chart\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors),\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.450165Z","iopub.execute_input":"2021-12-04T04:15:12.450523Z","iopub.status.idle":"2021-12-04T04:15:12.474419Z","shell.execute_reply.started":"2021-12-04T04:15:12.450494Z","shell.execute_reply":"2021-12-04T04:15:12.473552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Displaying Label , Value & percent in Pie Chart using \"textinfo\" parameter\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors),\n              textinfo='label+value+percent'\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.475901Z","iopub.execute_input":"2021-12-04T04:15:12.476552Z","iopub.status.idle":"2021-12-04T04:15:12.494712Z","shell.execute_reply.started":"2021-12-04T04:15:12.476504Z","shell.execute_reply":"2021-12-04T04:15:12.493659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Changing label orientation using \"insidetextorientation\" paramter\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors,line=dict(color='#797D7F', width=1.5)),\n              textinfo='percent',\n              hoverinfo='label+value',\n              textfont_size=15,\n              insidetextorientation='radial'\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.504627Z","iopub.execute_input":"2021-12-04T04:15:12.505483Z","iopub.status.idle":"2021-12-04T04:15:12.540710Z","shell.execute_reply.started":"2021-12-04T04:15:12.505428Z","shell.execute_reply":"2021-12-04T04:15:12.538865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Explode 4th Slice using \"pull\" parameter\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors),\n              textinfo='label+value+percent',\n              pull=[0, 0, 0, 0.2] #Explode 4th Slice\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.543691Z","iopub.execute_input":"2021-12-04T04:15:12.544214Z","iopub.status.idle":"2021-12-04T04:15:12.563426Z","shell.execute_reply.started":"2021-12-04T04:15:12.544167Z","shell.execute_reply":"2021-12-04T04:15:12.562696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Explode 3rd & 4th Slice using \"pull\" parameter\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors),\n              textinfo='label+value+percent',\n              pull=[0, 0, 0.2, 0.2]\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.564902Z","iopub.execute_input":"2021-12-04T04:15:12.565243Z","iopub.status.idle":"2021-12-04T04:15:12.580013Z","shell.execute_reply.started":"2021-12-04T04:15:12.565214Z","shell.execute_reply":"2021-12-04T04:15:12.579160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Simple Donut Chart\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors),\n              textinfo='label+value+percent',\n              hole=.4\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.581468Z","iopub.execute_input":"2021-12-04T04:15:12.582281Z","iopub.status.idle":"2021-12-04T04:15:12.603152Z","shell.execute_reply.started":"2021-12-04T04:15:12.582231Z","shell.execute_reply":"2021-12-04T04:15:12.602210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Explode 4th Slice using \"pull\" parameter\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ndata = go.Pie(\n              values= tickets,\n              labels= status,\n              marker=dict(colors=colors),\n              textinfo='label+value+percent',\n              hole=.4,\n              pull=[0, 0, 0, 0.2]\n              )\n\n\nlayout = go.Layout(\n                   title=dict(text = \"Tickets by Priority\",x=0.46,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.604711Z","iopub.execute_input":"2021-12-04T04:15:12.604982Z","iopub.status.idle":"2021-12-04T04:15:12.619838Z","shell.execute_reply.started":"2021-12-04T04:15:12.604915Z","shell.execute_reply":"2021-12-04T04:15:12.618981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"employment.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.621418Z","iopub.execute_input":"2021-12-04T04:15:12.622205Z","iopub.status.idle":"2021-12-04T04:15:12.643557Z","shell.execute_reply.started":"2021-12-04T04:15:12.622156Z","shell.execute_reply":"2021-12-04T04:15:12.642695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\n              values= employment.Unemployed,\n              labels= employment.Age,\n              textinfo='percent',\n              hoverinfo='label+value'\n              )\nlayout = go.Layout(\n                   title=dict(text = \"Unemployment Data\",x=0.44,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.644916Z","iopub.execute_input":"2021-12-04T04:15:12.645765Z","iopub.status.idle":"2021-12-04T04:15:12.674189Z","shell.execute_reply.started":"2021-12-04T04:15:12.645723Z","shell.execute_reply":"2021-12-04T04:15:12.673404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"suicide.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.675328Z","iopub.execute_input":"2021-12-04T04:15:12.675965Z","iopub.status.idle":"2021-12-04T04:15:12.692646Z","shell.execute_reply.started":"2021-12-04T04:15:12.675919Z","shell.execute_reply":"2021-12-04T04:15:12.691617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\n              values= suicide['suicides_no'],\n              labels= suicide['age'],\n              textinfo='percent',\n              hoverinfo='label+value'\n              )\nlayout = go.Layout(\n                   title=dict(text = \"Suicide Data\",x=0.44,y=0.95,font_size=20),\n                   width=800,\n                   height=650\n                  )\n\nfig = go.Figure(data=data,layout=layout)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.694081Z","iopub.execute_input":"2021-12-04T04:15:12.694330Z","iopub.status.idle":"2021-12-04T04:15:12.843552Z","shell.execute_reply.started":"2021-12-04T04:15:12.694298Z","shell.execute_reply":"2021-12-04T04:15:12.842616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display multiple Pie plots in one figure using Subplots\n\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\n\nAssignee = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \nOpen = [17,18,29,33,38,39,42]\n\n\n\n\n#Subplot initialization\nfig = make_subplots(\n                     rows=1, \n                     cols=2,\n                     subplot_titles=(\"Tickets by Priority\", \"Tickets by Assignee\"),\n                     \n                     specs=[[{'type':'domain'}, {'type':'domain'}]]\n                   )\n\n\n# Subplot - 1 (Add graph object trace to a figure)\nfig.add_trace(go.Pie(\n                     values= tickets,\n                     labels= status,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent'\n                    ),\n              row=1, col=1\n             )\n\n\nfig.add_trace(go.Pie(\n                     values= Open,\n                     labels= Assignee,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent'\n                    ),\n              row=1, col=2\n             )\n\nfig.update_layout(\n                    paper_bgcolor= '#FFFDE7',\n                    plot_bgcolor= '#FFFDE7',\n                    title=dict(text = \"Help Desk\",x=0.5,y=0.95),\n                    title_font_size=30\n                  )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.844862Z","iopub.execute_input":"2021-12-04T04:15:12.845100Z","iopub.status.idle":"2021-12-04T04:15:12.887431Z","shell.execute_reply.started":"2021-12-04T04:15:12.845070Z","shell.execute_reply":"2021-12-04T04:15:12.886854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display multiple Donut charts in one figure using Subplots\n\ntickets = [48 , 30 , 20 , 15]\nstatus = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\n\nAssignee = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] \nOpen = [17,18,29,33,38,39,42]\n\n\n\n\n#Subplot initialization\nfig = make_subplots(\n                     rows=1, \n                     cols=2,\n                     subplot_titles=(\"Tickets by Priority\", \"Tickets by Assignee\"),                     \n                     specs=[[{'type':'domain'}, {'type':'domain'}]]\n                   )\n\n\n# Subplot - 1 (Add graph object trace to a figure)\nfig.add_trace(go.Pie(\n                     values= tickets,\n                     labels= status,\n                     hole = .4,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent',\n                     hoverinfo='label'\n                    ),\n              row=1, col=1\n             )\n\n\nfig.add_trace(go.Pie(\n                     values= Open,\n                     labels= Assignee,\n                     hole = .4,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent',\n                     hoverinfo='label'\n                    ),\n              row=1, col=2\n             )\n\nfig.update_layout(\n                    paper_bgcolor= '#FFFDE7',\n                    plot_bgcolor= '#FFFDE7',\n                    title=dict(text = \"Help Desk\",x=0.5,y=0.95),\n                    title_font_size=30\n                  )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.888805Z","iopub.execute_input":"2021-12-04T04:15:12.889093Z","iopub.status.idle":"2021-12-04T04:15:12.924391Z","shell.execute_reply.started":"2021-12-04T04:15:12.889061Z","shell.execute_reply":"2021-12-04T04:15:12.923741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display multiple Pie & Donut plots in one figure using Subplots\n\ntickets = [48 , 30 , 20 , 15]\npriority = ['Low' , 'Medium' , 'High' , 'Critical']\ncolors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\ngroup = ['Service Desk' , 'Problem' , 'Application' , 'Change']\nstatus = ['Assigned', 'Pending' , 'New' , 'In Progress']\nseverity = ['Sev-4' , 'Sev-3' , 'sev-2' , 'sev-1']\n\n\n\n#Subplot initialization\nfig = make_subplots(\n                     rows=2, \n                     cols=2,\n                     subplot_titles=(\"Tickets by Priority\", \"Tickets by Severity\",\n                                     \"Tickets by Group\", \"Tickets by Status\"),    \n                     specs=[[{'type':'domain'}, {'type':'domain'}],[{'type':'domain'}, {'type':'domain'}]]\n                   )\n\n#Change Subplot title font size\nfor i in fig['layout']['annotations']:\n    i['font']['size'] = 17\n\n# Subplot - 1 (Add graph object trace to a figure)\nfig.add_trace(go.Pie(\n                     values= tickets,\n                     labels= priority,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent',\n                     hoverinfo='label',\n                    ),\n              row=1, col=1\n             )\n\n\n# Subplot - 2 (Add graph object trace to a figure)\nfig.add_trace(go.Pie(\n                     values= Open,\n                     labels= severity,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent',\n                     hoverinfo='label',\n                    ),\n              row=1, col=2\n             )\n\n\n# Subplot - 3 (Add graph object trace to a figure)\nfig.add_trace(go.Pie(\n                     values= tickets,\n                     labels= group,\n                     hole = .4,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent',\n                     hoverinfo='label'\n                    ),\n              row=2, col=1\n             )\n\n\n# Subplot - 4 (Add graph object trace to a figure)\nfig.add_trace(go.Pie(\n                     values= Open,\n                     labels= status,\n                     hole = .4,\n                     marker=dict(colors=colors),\n                     textinfo='label+value+percent',\n                     hoverinfo='label'\n                    ),\n              row=2, col=2\n             )\n\nfig.update_layout(\n                    paper_bgcolor= '#FFFDE7',\n                    plot_bgcolor= '#FFFDE7',\n                    title=dict(text = \"Help Desk\",x=0.49,y=0.97,font_size=30),\n                    width=950,\n                    height=900,\n                    showlegend=False\n                  )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.925972Z","iopub.execute_input":"2021-12-04T04:15:12.926483Z","iopub.status.idle":"2021-12-04T04:15:12.978858Z","shell.execute_reply.started":"2021-12-04T04:15:12.926438Z","shell.execute_reply":"2021-12-04T04:15:12.978187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Area Plot","metadata":{}},{"cell_type":"code","source":"# Simple Area plot\nx = np.arange(1,31)\ny = np.random.normal(10,11,size=30)\ny = np.square(y)\nfig = go.Figure()\nfig.add_trace(go.Scatter(x=x, y=y, fill='tozeroy')) # fill down to xaxis\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.980205Z","iopub.execute_input":"2021-12-04T04:15:12.980672Z","iopub.status.idle":"2021-12-04T04:15:12.993961Z","shell.execute_reply.started":"2021-12-04T04:15:12.980636Z","shell.execute_reply":"2021-12-04T04:15:12.993225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Changing color of area plot using marker color\nx = np.arange(1,31)\ny = np.random.normal(10,11,size=30)\ny = np.square(y)\nfig = go.Figure()\nfig.add_trace(go.Scatter(x=x, y=y, fill='tozeroy',marker = dict(color = 'gold'))) # fill down to xaxis\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:12.995533Z","iopub.execute_input":"2021-12-04T04:15:12.995947Z","iopub.status.idle":"2021-12-04T04:15:13.010273Z","shell.execute_reply.started":"2021-12-04T04:15:12.995891Z","shell.execute_reply":"2021-12-04T04:15:13.009428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=np.arange(1,7)\ny1 =  np.array([1,5,9,3,17,1])\ny2 = np.array([2,6,12,4,19,2])\ny3 = np.array([3,7,16,5,22,1])\ny4 = np.array([4,8,18,6,25,2])\n\n\nfig = go.Figure()\nfig.add_trace(go.Scatter(x=x, y=y1, fill='tozeroy',marker = dict(color = '#00b159'))) # fill down to xaxis\nfig.add_trace(go.Scatter(x=x, y=y2, fill='tonexty',marker = dict(color = '#ffc425'))) # fill to trace0 y\nfig.add_trace(go.Scatter(x=x, y=y3, fill='tonexty',marker = dict(color = '#3498DB'))) # fill to trace1 y\nfig.add_trace(go.Scatter(x=x, y=y4, fill='tonexty',marker = dict(color = '#ff3b30'))) # fill to trace2 y\nfig.update_layout(width = 980 , height = 600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.011641Z","iopub.execute_input":"2021-12-04T04:15:13.012523Z","iopub.status.idle":"2021-12-04T04:15:13.035351Z","shell.execute_reply.started":"2021-12-04T04:15:13.012465Z","shell.execute_reply":"2021-12-04T04:15:13.034519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Stacked Area Chart (Using stackgroup parameter)\n\nx=np.arange(1,7)\ny1 =  np.array([1,5,9,3,17,1])\ny2 = np.array([2,6,12,4,19,2])\ny3 = np.array([3,7,16,5,22,1])\ny4 = np.array([4,8,18,6,25,2])\n\n\nfig = go.Figure()\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y1, \n                          marker = dict(color = '#00b159'),\n                          stackgroup='one' # The stackgroup parameter is used to create a Stacked Area Chart\n                        )\n             )\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y2, \n                          marker = dict(color = '#ffc425'),\n                          stackgroup='one'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y3, \n                          marker = dict(color = '#3498DB'),\n                          stackgroup='one'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y4, \n                          marker = dict(color = '#ff3b30'),\n                          stackgroup='one'\n                        )\n             )\n\nfig.update_layout(width = 980 , height = 600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.036732Z","iopub.execute_input":"2021-12-04T04:15:13.037696Z","iopub.status.idle":"2021-12-04T04:15:13.062223Z","shell.execute_reply.started":"2021-12-04T04:15:13.037648Z","shell.execute_reply":"2021-12-04T04:15:13.061156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Stacked Area Chart\n\nx=['A','B','C','D','E']\ny1 =  np.array([30,10,40,20,60])\ny2 = np.array([10,20,10,20,10])\ny3 = np.array([5,10,5,10,5])\ny4 = np.array([10,5,10,5,10])\n\n\nfig = go.Figure()\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y1, \n                          marker = dict(color = '#00b159'), # Color of trace0\n                          stackgroup='one' # The stackgroup parameter is used to create a Stacked Area Chart\n                        )\n             )\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y2, \n                          marker = dict(color = '#ffc425'),\n                          stackgroup='one'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y3, \n                          marker = dict(color = '#3498DB'),\n                          stackgroup='one'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y4, \n                          marker = dict(color = '#ff3b30'),\n                          stackgroup='one'\n                        )\n             )\n\nfig.update_layout(width = 980 , height = 600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.063636Z","iopub.execute_input":"2021-12-04T04:15:13.064288Z","iopub.status.idle":"2021-12-04T04:15:13.085930Z","shell.execute_reply.started":"2021-12-04T04:15:13.064250Z","shell.execute_reply":"2021-12-04T04:15:13.084951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Stacked Area Chart Without Boundary Lines (Using mode = 'none')\n\nx=['A','B','C','D','E']\ny1 =  np.array([30,10,40,20,60])\ny2 = np.array([10,20,10,20,10])\ny3 = np.array([5,10,5,10,5])\ny4 = np.array([10,5,10,5,10])\n\n\nfig = go.Figure()\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y1, \n                          mode='none',\n                          stackgroup='one'\n                        )\n             )\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y2, \n                          mode='none',\n                          stackgroup='one'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y3, \n                          mode='none',\n                          stackgroup='one'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y4, \n                          mode='none',\n                          stackgroup='one'\n                        )\n             )\n\nfig.update_layout(width = 980 , height = 600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.087450Z","iopub.execute_input":"2021-12-04T04:15:13.087729Z","iopub.status.idle":"2021-12-04T04:15:13.114425Z","shell.execute_reply.started":"2021-12-04T04:15:13.087694Z","shell.execute_reply":"2021-12-04T04:15:13.113349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#100 Percent Stacked Area Chart (Using groupnorm parameter)\n\n\nx=['A','B','C','D','E']\ny1 =  np.array([30,10,40,20,60])\ny2 = np.array([10,20,10,20,10])\ny3 = np.array([5,10,5,10,5])\ny4 = np.array([10,5,10,5,10])\n\n\nfig = go.Figure()\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y1, \n                          marker = dict(color = '#00b159'),\n                          stackgroup='one',\n                          groupnorm='percent' #normalization for the sum of the stackgroup\n                        )\n             )\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y2, \n                          marker = dict(color = '#ffc425'),\n                          stackgroup='one',\n                          groupnorm='percent'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y3, \n                          marker = dict(color = '#3498DB'),\n                          stackgroup='one',\n                          groupnorm='percent'\n                        )\n             )\n\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y4, \n                          marker = dict(color = '#ff3b30'),\n                          stackgroup='one',\n                          groupnorm='percent'\n                        )\n             )\n\nfig.update_layout(\n                  width = 990, \n                  height = 650,\n                  xaxis_type='category',\n                  yaxis=dict(\n                              range=[1, 100],\n                              ticksuffix='%'\n                             )\n                 )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.115826Z","iopub.execute_input":"2021-12-04T04:15:13.117052Z","iopub.status.idle":"2021-12-04T04:15:13.148350Z","shell.execute_reply.started":"2021-12-04T04:15:13.117016Z","shell.execute_reply":"2021-12-04T04:15:13.147369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Area Chart with interioir filling using  fill='tonexty'\n\nx=['A','B','C','D','E']\ny1 =  np.array([30,10,40,20,60])\ny2 = np.array([10,20,10,20,10])\n\n\nfig = go.Figure()\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y1, \n                          marker = dict(color = '#00b159'),\n                          fill = None\n                        )\n             )\n\nfig.add_trace(go.Scatter(\n                          x=x,\n                          y=y2, \n                          fill='tonexty', # fill to trace0 y\n                          marker = dict(color = '#ffc425'),\n                        )\n             )\n\n\nfig.update_layout(width = 980 , height = 600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.150188Z","iopub.execute_input":"2021-12-04T04:15:13.151015Z","iopub.status.idle":"2021-12-04T04:15:13.170075Z","shell.execute_reply.started":"2021-12-04T04:15:13.150959Z","shell.execute_reply":"2021-12-04T04:15:13.169316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Color scales in Plotly Express","metadata":{}},{"cell_type":"code","source":"#Sequential Color scales\nfig = px.colors.sequential.swatches()\nfig.update_layout(width = 990 , height = 1760)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.171823Z","iopub.execute_input":"2021-12-04T04:15:13.172177Z","iopub.status.idle":"2021-12-04T04:15:13.297735Z","shell.execute_reply.started":"2021-12-04T04:15:13.172132Z","shell.execute_reply":"2021-12-04T04:15:13.296906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Cyclical Color scales\nfig = px.colors.cyclical.swatches_cyclical()\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.299086Z","iopub.execute_input":"2021-12-04T04:15:13.300002Z","iopub.status.idle":"2021-12-04T04:15:13.485524Z","shell.execute_reply.started":"2021-12-04T04:15:13.299956Z","shell.execute_reply":"2021-12-04T04:15:13.484575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Cyclical Color scales\nfig = px.colors.cyclical.swatches()\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.486828Z","iopub.execute_input":"2021-12-04T04:15:13.487081Z","iopub.status.idle":"2021-12-04T04:15:13.532317Z","shell.execute_reply.started":"2021-12-04T04:15:13.487051Z","shell.execute_reply":"2021-12-04T04:15:13.531446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Diverging Color scales\nfig = px.colors.diverging.swatches().update_layout(margin_b=10)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.533495Z","iopub.execute_input":"2021-12-04T04:15:13.534082Z","iopub.status.idle":"2021-12-04T04:15:13.606048Z","shell.execute_reply.started":"2021-12-04T04:15:13.534041Z","shell.execute_reply":"2021-12-04T04:15:13.605085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Qualitative Color scales\nfig = px.colors.qualitative.swatches()\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.607277Z","iopub.execute_input":"2021-12-04T04:15:13.607528Z","iopub.status.idle":"2021-12-04T04:15:13.671022Z","shell.execute_reply.started":"2021-12-04T04:15:13.607498Z","shell.execute_reply":"2021-12-04T04:15:13.670146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Sunburst Chart","metadata":{}},{"cell_type":"code","source":"insurance.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.672229Z","iopub.execute_input":"2021-12-04T04:15:13.672959Z","iopub.status.idle":"2021-12-04T04:15:13.689233Z","shell.execute_reply.started":"2021-12-04T04:15:13.672923Z","shell.execute_reply":"2021-12-04T04:15:13.687399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Simple Sunburst Chart\n\nfig = px.sunburst(insurance, path=['region', 'smoker' , 'sex'], values='charges')\nfig.update_layout (height = 800 , width = 800)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.690298Z","iopub.execute_input":"2021-12-04T04:15:13.690542Z","iopub.status.idle":"2021-12-04T04:15:13.841181Z","shell.execute_reply.started":"2021-12-04T04:15:13.690512Z","shell.execute_reply":"2021-12-04T04:15:13.840225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.sunburst(insurance, path=['region', 'smoker' , 'sex'], values='charges' , color= 'charges')\nfig.update_layout (height = 800 , width = 800)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:13.842774Z","iopub.execute_input":"2021-12-04T04:15:13.843102Z","iopub.status.idle":"2021-12-04T04:15:14.003634Z","shell.execute_reply.started":"2021-12-04T04:15:13.843058Z","shell.execute_reply":"2021-12-04T04:15:14.002712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using inbuilt color scales in Sunburst Chart\n\nfig = px.sunburst(\n                   insurance,\n                   path=['region', 'smoker' , 'sex'], \n                   values='charges' , color= 'charges' , \n                   color_continuous_scale=px.colors.sequential.Aggrnyl\n                 )\n\nfig.update_layout (height = 800 , width = 800)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:14.004837Z","iopub.execute_input":"2021-12-04T04:15:14.005524Z","iopub.status.idle":"2021-12-04T04:15:14.156032Z","shell.execute_reply.started":"2021-12-04T04:15:14.005475Z","shell.execute_reply":"2021-12-04T04:15:14.155301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using color scales in Sunburst Chart\n\nfig = px.sunburst(\n                   insurance, \n                   path=['region', 'smoker' , 'sex'], \n                   values='charges' , \n                   color= 'charges' , \n                   color_continuous_scale=[\"#8BC34A\", \"#FF6F00\"] #Explicitly Constructing a Color Sequence\n                  )\n\nfig.update_layout (height = 800 , width = 800)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:14.156975Z","iopub.execute_input":"2021-12-04T04:15:14.157685Z","iopub.status.idle":"2021-12-04T04:15:14.309419Z","shell.execute_reply.started":"2021-12-04T04:15:14.157646Z","shell.execute_reply":"2021-12-04T04:15:14.308420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"suicide.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:14.310528Z","iopub.execute_input":"2021-12-04T04:15:14.310809Z","iopub.status.idle":"2021-12-04T04:15:14.330102Z","shell.execute_reply.started":"2021-12-04T04:15:14.310780Z","shell.execute_reply":"2021-12-04T04:15:14.329122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.sunburst(suicide, path=['sex', 'age' , 'generation'], values='suicides_no')\nfig.update_layout (height = 900 , width = 900)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:14.331271Z","iopub.execute_input":"2021-12-04T04:15:14.331497Z","iopub.status.idle":"2021-12-04T04:15:14.986326Z","shell.execute_reply.started":"2021-12-04T04:15:14.331471Z","shell.execute_reply":"2021-12-04T04:15:14.985212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.sunburst(\n                   suicide, path=['sex', 'age' , 'generation'], \n                   values='suicides_no' , \n                   color= 'suicides_no' , \n                   color_continuous_scale=[\"#8BC34A\",\"#FF6F00\"]\n                 )\n\nfig.update_layout (height = 900 , width = 900)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:14.987937Z","iopub.execute_input":"2021-12-04T04:15:14.988283Z","iopub.status.idle":"2021-12-04T04:15:15.660104Z","shell.execute_reply.started":"2021-12-04T04:15:14.988246Z","shell.execute_reply":"2021-12-04T04:15:15.658986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tables & Figure Factory Tables","metadata":{}},{"cell_type":"code","source":"rating","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.661214Z","iopub.execute_input":"2021-12-04T04:15:15.661546Z","iopub.status.idle":"2021-12-04T04:15:15.678964Z","shell.execute_reply.started":"2021-12-04T04:15:15.661495Z","shell.execute_reply":"2021-12-04T04:15:15.678041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Basic table in Plotly\n\nfig = go.Figure(data=[go.Table(\n                                 header=dict(\n                                              values=list(rating.columns),\n                                             ),\n                                 cells=dict(values=[\n                                                     rating['Strongly Agree'] , \n                                                     rating['Agree'] , \n                                                     rating['Neutral'] ,\n                                                     rating['Disagree'] , \n                                                     rating['Strongly Disagree'],\n                                                     rating['Total'],\n                                                     rating['Strongly Agree (%)'],\n                                                     rating['Agree (%)'],\n                                                     rating['Neutral (%)'],\n                                                     rating['Disagree (%)'],\n                                                     rating['Strongly Disagree (%)']\n                                                    ],\n                                             )\n                                    )\n                        ]\n               )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.680385Z","iopub.execute_input":"2021-12-04T04:15:15.680722Z","iopub.status.idle":"2021-12-04T04:15:15.700335Z","shell.execute_reply.started":"2021-12-04T04:15:15.680676Z","shell.execute_reply":"2021-12-04T04:15:15.699544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Styled Table in Plotly\nfig = go.Figure(data=[go.Table(\n                                 header=dict(\n                                              values=list(rating.columns),\n                                              fill_color='paleturquoise',\n                                              align='left'\n                                             ),\n                                 cells=dict(values=[\n                                                     rating['Strongly Agree'] , \n                                                     rating['Agree'] , \n                                                     rating['Neutral'] ,\n                                                     rating['Disagree'] , \n                                                     rating['Strongly Disagree'],\n                                                     rating['Total'],\n                                                     rating['Strongly Agree (%)'],\n                                                     rating['Agree (%)'],\n                                                     rating['Neutral (%)'],\n                                                     rating['Disagree (%)'],\n                                                     rating['Strongly Disagree (%)']\n                                                    ],\n                                fill_color='lavender',\n                                align='center'))\n                     ]\n               )\nfig.update_layout(width=990, height=350)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.701542Z","iopub.execute_input":"2021-12-04T04:15:15.702480Z","iopub.status.idle":"2021-12-04T04:15:15.722530Z","shell.execute_reply.started":"2021-12-04T04:15:15.702436Z","shell.execute_reply":"2021-12-04T04:15:15.721891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Styled Table in Plotly\n\nfig = go.Figure(data=[go.Table(\n                                 header=dict(\n                                              values=list(insurance.columns), # Header values\n                                              line_color='black', # Line Color of header \n                                              fill_color='orange', # background color of header\n                                              align='center', # Align header at center\n                                              height=40, # Height of Header\n                                              font=dict(color='white', size=18), # Font size & color of header text\n                                             ),\n                                 cells=dict(values=[\n                                                     insurance.age , # Column values\n                                                     insurance.sex, \n                                                     insurance.bmi,\n                                                     insurance.children, \n                                                     insurance.smoker,\n                                                     insurance.region,\n                                                     insurance.charges\n                                                    ],\n                                            line_color='darkgrey', # Line color of the cell\n                                            fill_color='lightcyan', # Color of the cell\n                                            align='left'  # Align text to left in cell\n                                           )\n                               )\n                     ]\n               )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.724130Z","iopub.execute_input":"2021-12-04T04:15:15.724612Z","iopub.status.idle":"2021-12-04T04:15:15.863706Z","shell.execute_reply.started":"2021-12-04T04:15:15.724563Z","shell.execute_reply":"2021-12-04T04:15:15.862928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Styled Table in Plotly\n\nrowEvenColor = 'lightgrey'\nrowOddColor = 'white'\nfig = go.Figure(data=[go.Table(  columnwidth = [80,80,80,80,80,80,120,80,80,80,120],\n                                 header=dict(\n                                              values=[\n                                                     '<b>Strongly Agree</b>',\n                                                     '<b>Agree</b>',\n                                                     '<b>Neutral</b>',\n                                                     '<b>Disagree</b>',\n                                                     '<b>Strongly Disagree</b>',\n                                                     '<b>Total</b>',\n                                                     '<b>Strongly Agree (%)</b>',\n                                                     '<b>Agree (%)</b>',\n                                                     '<b>Neutral (%)</b>',\n                                                     '<b>Disagree (%)</b>',\n                                                     '<b>Strongly Disagree (%)</b>'\n                                                     ],\n                                              fill_color='#8BC34A',\n                                              line = dict(color = '#689F38' , width = 4),\n                                              align='center',\n                                              font_size=12,\n                                              font_color = 'white'\n                                             ),\n                                 cells=dict(values=[\n                                                     rating['Strongly Agree'] , \n                                                     rating['Agree'] , \n                                                     rating['Neutral'] ,\n                                                     rating['Disagree'] , \n                                                     rating['Strongly Disagree'],\n                                                     rating['Total'],\n                                                     rating['Strongly Agree (%)'],\n                                                     rating['Agree (%)'],\n                                                     rating['Neutral (%)'],\n                                                     rating['Disagree (%)'],\n                                                     rating['Strongly Disagree (%)']\n                                                    ],\n                                             fill_color = [[rowOddColor,rowEvenColor]*5],\n                                             line = dict(color = 'lightgreen' , width = 4),\n                                             align ='center',\n                                             font_size=12,\n                                             font = dict(color = 'darkslategray', size = 11),\n                                             height=40\n                                            )\n                                )\n                     ]\n               )\nfig.update_layout(width=990, height=500)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.865218Z","iopub.execute_input":"2021-12-04T04:15:15.865681Z","iopub.status.idle":"2021-12-04T04:15:15.904756Z","shell.execute_reply.started":"2021-12-04T04:15:15.865639Z","shell.execute_reply":"2021-12-04T04:15:15.903854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create simple table using create_table function\n\nfig = ff.create_table(insurance.tail(5))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.906153Z","iopub.execute_input":"2021-12-04T04:15:15.906463Z","iopub.status.idle":"2021-12-04T04:15:15.962355Z","shell.execute_reply.started":"2021-12-04T04:15:15.906422Z","shell.execute_reply":"2021-12-04T04:15:15.961497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create simple table using create_table function\n\nfig = ff.create_table(insurance.tail(5),height_constant=50)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:15.964059Z","iopub.execute_input":"2021-12-04T04:15:15.964925Z","iopub.status.idle":"2021-12-04T04:15:16.003288Z","shell.execute_reply.started":"2021-12-04T04:15:15.964887Z","shell.execute_reply":"2021-12-04T04:15:16.002674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using color scales in table\n\ncolorscale = [[0, 'red'],[.5, '#DCE775'],[1, '#C0CA33']]\nfig = ff.create_table(insurance.tail(5),height_constant=50,colorscale=colorscale)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.004470Z","iopub.execute_input":"2021-12-04T04:15:16.005267Z","iopub.status.idle":"2021-12-04T04:15:16.047675Z","shell.execute_reply.started":"2021-12-04T04:15:16.005230Z","shell.execute_reply":"2021-12-04T04:15:16.046715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Changing font color\n\ncolorscale = [[0, 'red'],[.5, '#DCE775'],[1, '#C0CA33']]\nfont=['white', '#212121' , 'red']\nfig = ff.create_table(insurance.tail(5),height_constant=50,colorscale=colorscale,font_colors=font)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.048840Z","iopub.execute_input":"2021-12-04T04:15:16.049067Z","iopub.status.idle":"2021-12-04T04:15:16.090539Z","shell.execute_reply.started":"2021-12-04T04:15:16.049037Z","shell.execute_reply":"2021-12-04T04:15:16.089574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Changing font size using \"fig.layout.annotations[i].font.size\"\n\ncolorscale = [[0, 'red'],[.5, '#DCE775'],[1, '#C0CA33']]\nfont=['white', '#212121' , 'red']\nfig = ff.create_table(insurance.tail(5),height_constant=50,colorscale=colorscale,font_colors=font)\nfor i in range(len(fig.layout.annotations)):\n    fig.layout.annotations[i].font.size = 17\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.091935Z","iopub.execute_input":"2021-12-04T04:15:16.092158Z","iopub.status.idle":"2021-12-04T04:15:16.181166Z","shell.execute_reply.started":"2021-12-04T04:15:16.092132Z","shell.execute_reply":"2021-12-04T04:15:16.180586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colorscale = [[0, 'red'],[.5, '#DCE775'],[1, '#C0CA33']]\nfont=['white', '#212121' , 'red']\nfig = ff.create_table(insurance.tail(5),height_constant=50,colorscale=colorscale,font_colors=font)\nfor i in range(len(fig.layout.annotations)):\n    fig.layout.annotations[i].font.size = 12   \nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.182554Z","iopub.execute_input":"2021-12-04T04:15:16.183005Z","iopub.status.idle":"2021-12-04T04:15:16.264975Z","shell.execute_reply.started":"2021-12-04T04:15:16.182974Z","shell.execute_reply":"2021-12-04T04:15:16.263920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"canada.loc[:, ['India','Pakistan','China']].head(6)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.266266Z","iopub.execute_input":"2021-12-04T04:15:16.266534Z","iopub.status.idle":"2021-12-04T04:15:16.281733Z","shell.execute_reply.started":"2021-12-04T04:15:16.266502Z","shell.execute_reply":"2021-12-04T04:15:16.277722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Displaying tables along with graphs\n\nimport plotly.graph_objs as go\nimport plotly.figure_factory as ff\n\n# Add table data\ntable_data = canada.loc[:, ['India','Pakistan','China']].head(6)\n\n\n# Initialize a figure with ff.create_table(table_data)\nfig = ff.create_table(table_data, height_constant=60)\n\n\n# Make traces for graph\nfig.add_trace( go.Scatter(\n                    x = canada.index.values,\n                    y = canada['China'],\n                    mode = 'lines',\n                    name = 'China',\n                    xaxis='x2', yaxis='y2'\n                   )\n              )\n\n\n# Make traces for graph\nfig.add_trace( go.Scatter(\n                    x = canada.index.values,\n                    y = canada['India'],\n                    mode = 'lines',\n                    name = 'India',\n                    xaxis='x2', yaxis='y2'\n                   )\n             )\n\n# Make traces for graph\nfig.add_trace( go.Scatter(\n                        x = canada.index.values,\n                        y = canada['Pakistan'],\n                        mode = 'lines',\n                        name = 'Pakistan',\n                        xaxis='x2', yaxis='y2'\n                      )\n             )\n\n\n\nfig.update_layout(\n                    title=dict(text = \"Immigration Data\",x=0.5,y=0.98), # Figure title along with Alignment values\n                    paper_bgcolor= '#dbdbdb', # Figure background \n                    margin = {'t':50, 'b':100},\n                    xaxis = {'domain': [0, .5] , 'title' : 'Migrants'},\n                    xaxis2 = {'domain': [0.6, 1.] , 'title' : 'Year'},\n                    yaxis2 = {'anchor': 'x2', 'title': 'Count'},\n                    width = 990,\n                    height = 600\n                  )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.283753Z","iopub.execute_input":"2021-12-04T04:15:16.284798Z","iopub.status.idle":"2021-12-04T04:15:16.340177Z","shell.execute_reply.started":"2021-12-04T04:15:16.284733Z","shell.execute_reply":"2021-12-04T04:15:16.339559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Displaying tables along with graphs\n\nimport plotly.graph_objs as go\nimport plotly.figure_factory as ff\n\n# Add table data\ntable_data = canada.loc[:, ['India','Pakistan','China' , 'Australia' , 'Germany' , 'Austria']].head(6)\n\n\n# Initialize a figure with ff.create_table(table_data)\nfig = ff.create_table(table_data, height_constant=60)\n\n\n# Make traces for graph\nfig.add_trace( go.Scatter(\n                    x = canada.index.values,\n                    y = canada['China'],\n                    mode = 'lines',\n                    name = 'China',\n                    xaxis='x2', yaxis='y2'\n                   )\n              )\n\nfig.add_trace( go.Scatter(\n                    x = canada.index.values,\n                    y = canada['India'],\n                    mode = 'lines',\n                    name = 'India',\n                    xaxis='x2', yaxis='y2'\n                   )\n             )\n\nfig.add_trace( go.Scatter(\n                        x = canada.index.values,\n                        y = canada['Pakistan'],\n                        mode = 'lines',\n                        name = 'Pakistan',\n                        xaxis='x2', yaxis='y2'\n                      )\n             )\n\n\n\nfig.update_layout(\n    title_text = '2016 Hockey Stats',\n    height = 800,\n    margin = {'t':50, 'l':20},\n    yaxis = {'domain': [0, .3]},\n    yaxis2 = {'domain': [.4, 1], 'anchor': 'x2', 'title': 'Goals'},\n    xaxis2 = {'anchor': 'y2'},\n)\n\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.341556Z","iopub.execute_input":"2021-12-04T04:15:16.342051Z","iopub.status.idle":"2021-12-04T04:15:16.407703Z","shell.execute_reply.started":"2021-12-04T04:15:16.342017Z","shell.execute_reply":"2021-12-04T04:15:16.406826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Bubble Chart","metadata":{}},{"cell_type":"code","source":"#Simple Bubble Chart\nx = np.arange(1,10)\ny = np.random.randint(1,100,9)\nop = np.random.uniform(0.2,1 ,9)\ndata = go.Scatter(\n                  x = x,\n                  y = y,\n                  mode = 'markers',\n                  marker = dict(size = y),\n                 )\n\nfig = go.Figure(data=data)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.409271Z","iopub.execute_input":"2021-12-04T04:15:16.409776Z","iopub.status.idle":"2021-12-04T04:15:16.423720Z","shell.execute_reply.started":"2021-12-04T04:15:16.409732Z","shell.execute_reply":"2021-12-04T04:15:16.422870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = np.arange(1,10)\ny = np.random.randint(1,100,9)\nop = np.random.uniform(0.2,1 ,9)\ndata = go.Scatter(\n                  x = x,\n                  y = y,\n                  mode = 'markers',\n                  marker = dict(size = y,opacity = op), # Changing opacity & size of bubbles\n                  )\n\nfig = go.Figure(data=data)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:15:16.425319Z","iopub.execute_input":"2021-12-04T04:15:16.425841Z","iopub.status.idle":"2021-12-04T04:15:16.442903Z","shell.execute_reply.started":"2021-12-04T04:15:16.425795Z","shell.execute_reply":"2021-12-04T04:15:16.442015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"suicide.head()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Bubble Chart using plotly.express\nfig = px.scatter(\n                 suicide.query(\"year==1987\"), \n                 x=\"population\", \n                 y=\"suicides_no\",\n                 size=\"suicides_no\", \n                 color=\"age\",\n                 hover_name=\"country\",\n                 size_max=60\n                )\nfig.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Sankey Diagram","metadata":{}},{"cell_type":"code","source":"#Simple Sankey Diagram\n\nfig = go.Figure(\n                 go.Sankey(\n                            node = {\n                                     \"label\": [\"India\", \"USA\", \"China\", \"Pakistan\", \"Bangladesh\", \"Mexico\"],\n                                   },\n                            link = {\n                                    \"source\": [0, 1, 2, 3, 4, 0, 2, 5],\n                                    \"target\": [1, 2, 3, 4, 5, 3, 5, 3],\n                                    \"value\": [300, 400, 200, 450, 700, 200,150, 200]\n                                   }\n                          )\n               )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:16:03.948739Z","iopub.execute_input":"2021-12-04T04:16:03.949404Z","iopub.status.idle":"2021-12-04T04:16:03.982568Z","shell.execute_reply.started":"2021-12-04T04:16:03.949353Z","shell.execute_reply":"2021-12-04T04:16:03.981699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Simple Sankey Diagram\n\nfig = go.Figure(\n                 go.Sankey(\n                            node = dict(\n                                          thickness = 40, # Changing thickness of nodes\n                                          color = \"lightgreen\", # Changing color of the node                         \n                                          line = dict(color = \"red\", width = 0.5), # Changing line color \n                                          label = [\"India\", \"USA\", \"China\", \"Pakistan\", \"Bangladesh\", \"Mexico\"],\n\n                                        ),\n                            link = {\n                                    \"source\": [0, 1, 2, 3, 4, 0, 2, 5],\n                                    \"target\": [1, 2, 3, 4, 5, 3, 5, 3],\n                                    \"value\": [300, 400, 200, 450, 550, 200,150, 200]\n                                   }\n                          )\n               )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:16:03.984502Z","iopub.execute_input":"2021-12-04T04:16:03.985146Z","iopub.status.idle":"2021-12-04T04:16:04.011406Z","shell.execute_reply.started":"2021-12-04T04:16:03.985099Z","shell.execute_reply":"2021-12-04T04:16:04.010430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Simple Sankey Diagram\n\nfig = go.Figure(\n                 go.Sankey(\n                            node = {\n                                     \"label\": [\"Married: NO\", \"Married: Yes\", \n                                               \"Pet: No\", \"Pet: Yes\", \n                                               \"Happy: Yes\", \"Happy: No\"],\n                                     \"color\" : px.colors.qualitative.Set3 # Node color\n                                   },\n                            link = dict(\n                                         source = [0, 0, 1, 1, 2, 2, 3, 5],\n                                         target = [2, 3, 2, 3, 5, 4, 4, 3],\n                                         value = [200, 300, 400, 600, 150, 350,700],\n                                         color = px.colors.qualitative.Set2 # Color of links\n                                        )\n                          )\n               )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T04:16:04.552579Z","iopub.execute_input":"2021-12-04T04:16:04.553514Z","iopub.status.idle":"2021-12-04T04:16:04.571843Z","shell.execute_reply.started":"2021-12-04T04:16:04.553462Z","shell.execute_reply":"2021-12-04T04:16:04.570774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## END","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}