{"cells":[{"metadata":{},"cell_type":"markdown","source":"* * <font size=\"+3\" color=purple ><b><center><u>Cheatsheet - 70+ Plotly Charts</u></center></b></font>"},{"metadata":{},"cell_type":"markdown","source":"# Objective\n\nThe aim of this kernel is provide all essential and most commonly used ggplot charts in a single page.This kernel will hold almost all charts with different attributes used for them.It could be a great time saver for you.Just utilize it anytime when you are working on data visualizations. \n\n**Note**:\nI made this kernel with different types of plots(70+ in count) which required multiple tabular datasets to be used from kaggle platform to showcase interesting insights from them."},{"metadata":{},"cell_type":"markdown","source":"<a id=\"top\"></a>\n\n<div class=\"list-group\" id=\"list-tab\" role=\"tablist\">\n<h3 class=\"list-group-item list-group-item-action active\" data-toggle=\"list\"  role=\"tab\" aria-controls=\"home\">Table of content</h3>\n\n* [Starters](#0)\n\n<font color=\"purple\" size=+1><b>Scatter</b></font>\n* [1. Basic Scatter plot](#1)\n* [2. Scatter - Numerical](#2)\n* [3. Scatter - Categorical ](#3)\n* [4. Scatter - Color and size](#4)\n* [5. Line - Scatter](#5)\n* [6. Random sample scatter Plot](#6) \n    \n    \n<font color=\"magenta\" size=+1><b>Bar</b></font>\n* [7. Basic Bar chart](#7)\n* [8. stacked Bar chart](#8)\n* [9. Bar Chart - Grouped](#9)\n* [10. Graph Objects - Bar Chart](#10)\n* [11. Graph Objects - Grouped Chart](#11) \n* [12. Graph Objects - Stacked Chart](#12) \n* [13. Graph Object Customization of Colors](#13) \n* [14. Graphh Objects - Relative Bar mode](#14) \n* [15. Category Ascending order or descending Order](#15) \n* [16. Horizontal Stacked bar chart](#16)\n* [17. Bar Chart - Horizontal](#17)\n    \n\n<font color=\"green\" size=+1><b>Pie</b></font>\n    \n* [20. Basic Pie Plot](#20)\n* [21. Repeated labels Pie](#21)\n* [22. Customized Pie- Gradient & Text](#22)\n* [23. Donut Plot](#23)\n* [24. Ring Plot](#24)"},{"metadata":{"trusted":true},"cell_type":"code","source":"pip install chart_studio","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd \nimport seaborn as sns\nimport numpy as np\nimport plotly.express as px \nimport plotly.graph_objects as go \nimport plotly.figure_factory as ff\nimport chart_studio.plotly as py\nimport plotly as ky","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv(\"../input/100-sales-record/100-Sales-Records/100 Sales Records.csv\",parse_dates=[\"Order Date\"]) \ndf1 = pd.read_csv(\"../input/stroke-prediction-dataset/healthcare-dataset-stroke-data.csv\") \ndf1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df[\"Order year\"] =df[\"Order Date\"].dt.year","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"1\"></a>\n<font color=\"purple\" size=+2.5><b>1. Basic Simple Scatter Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"2\"></a>\n<font color=\"purple\" size=+2.5><b>2. Scatter - Numerical plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.scatter(df,x=\"Units Sold\",y=\"Unit Price\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"3\"></a>\n<font color=\"purple\" size=+2.5><b>3.Scatter - Category plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.scatter(df,x=\"Units Sold\",y=\"Unit Price\",color=\"Country\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"4\"></a>\n<font color=\"purple\" size=+2.5><b>4.Scatter Color and size plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.scatter(df,x=\"Units Sold\",y=\"Unit Price\",color=\"Region\",size=\"Unit Cost\",hover_data=[\"Sales Channel\"])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"5\"></a>\n<font color=\"purple\" size=+2.5><b>5.Scatter - Line plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"df1 = px.data.gapminder().query(\"continent == 'Oceania'\")\nfig = px.line(df1, x='year', y='lifeExp', color='country')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"N = 1000\nt = np.linspace(0, 10, 100)\ny = np.sin(t)\n\nfig = go.Figure(data=go.Scatter(x=t, y=y, mode='markers'))\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"N = 100\nrandom_x = np.linspace(0, 1, N)\nrandom_y0 = np.random.randn(N) + 5\nrandom_y1 = np.random.randn(N)\nrandom_y2 = np.random.randn(N) - 5\n\nfig = go.Figure()\n\n# Add traces\nfig.add_trace(go.Scatter(x=random_x, y=random_y0,\n                    mode='markers',\n                    name='markers'))\nfig.add_trace(go.Scatter(x=random_x, y=random_y1,\n                    mode='lines+markers',\n                    name='lines+markers'))\nfig.add_trace(go.Scatter(x=random_x, y=random_y2,\n                    mode='lines',\n                    name='lines'))\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure(data=go.Scatter(\n    x=[1, 2, 3, 4],\n    y=[10, 11, 12, 13],\n    mode='markers',\n    marker=dict(size=[40, 60, 80, 100],\n                color=[0, 1, 2, 3])\n))\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure(data = go.Scatter(x=df[\"Country\"],\n                                  y=df[\"Total Profit\"],\n                                  mode='markers',\n                                  marker_color=df[\"Total Profit\"])) \nfig.update_layout(title=\"Total Cost over an country wise\")\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"6\"></a>\n<font color=\"purple\" size=+2.5><b>6.Random Sample Scatter plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"N = 100000\nfig = go.Figure(data=go.Scattergl(\n    x = np.random.randn(N),\n    y = np.random.randn(N),\n    mode='markers',\n    marker=dict(\n        color=np.random.randn(N),\n        colorscale='plasma',\n        line_width=1\n    )\n))\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"7\"></a>\n<font color=\"purple\" size=+2.5><b>7.Basic Bar Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.bar(df,x=\"Country\",y=\"Total Cost\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df2 = pd.pivot_table(df,values=[\"Total Cost\"],index=['Country','Sales Channel'],aggfunc={'Total Cost':np.sum}) ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"8\"></a>\n<font color=\"purple\" size=+2.5><b>8.Stacked bar chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.bar(df,x='Country',y=\"Total Cost\",color=\"Sales Channel\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.bar(df,x=\"Country\",y=\"Total Cost\",hover_data=[\"Region\",\"Sales Channel\"],height=500,color=\"Total Cost\") \nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"px.bar(df,x=\"Sales Channel\",y=\"Total Cost\",color=\"Region\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"9\"></a>\n<font color=\"purple\" size=+2.5><b>9.Grouped Bar Chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.bar(df,x=\"Sales Channel\",y=\"Total Cost\",color=\"Region\",barmode=\"group\",height=500)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df[\"Region\"].unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"px.bar(df,x=\"Sales Channel\",y=\"Total Cost\",color=\"Region\",barmode=\"group\",facet_row=\"Sales Channel\",facet_col=\"Region\",height=500,\n       category_orders={\"Region\":['Australia and Oceania', 'Central America and the Caribbean',\n       'Europe', 'Sub-Saharan Africa', 'Asia',\n       'Middle East and North Africa', 'North America'],\n                       \"Sales Channel\":[\"Offline\",\"Online\"]})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"names = [\"Richad\",\"Teja\",\"kumar\"] \nMarks = [90,100,80]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"10\"></a>\n<font color=\"purple\" size=+2.5><b>10.Graph Objects bar chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"go.Figure([go.Bar(x=names,y=Marks)])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"11\"></a>\n<font color=\"purple\" size=+2.5><b>11. Graph Objects grouped bar chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"animals=['giraffes', 'orangutans', 'monkeys']\n\nfig = go.Figure(data=[\n    go.Bar(name='SF Zoo', x=animals, y=[20, 14, 23]),\n    go.Bar(name='LA Zoo', x=animals, y=[12, 18, 29])\n])\n# Change the bar mode\nfig.update_layout(barmode='group')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"12\"></a>\n<font color=\"purple\" size=+2.5><b>12.Graph objects stacked bar chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"animals=['giraffes', 'orangutans', 'monkeys']\n\nfig = go.Figure(data=[\n    go.Bar(name='SF Zoo', x=animals, y=[20, 14, 23]),\n    go.Bar(name='LA Zoo', x=animals, y=[12, 18, 29])\n])\n# Change the bar mode\nfig.update_layout(barmode='stack')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x = ['Product A', 'Product B', 'Product C']\ny = [20, 14, 23]\n\n# Use textposition='auto' for direct text\nfig = go.Figure(data=[go.Bar(\n            x=x, y=y,\n            text=y,\n            textposition='auto',\n        )]) \nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.bar(df,x=\"Country\",y=\"Total Profit\",text=df[\"Total Profit\"]) \nfig.update_traces(texttemplate='%{text:.2s}',textposition=\"outside\") \n#fig.update_layout(uniformtext_minsize=180, uniformtext_mode='hide') \nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',\n          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']\n\nfig = go.Figure()\nfig.add_trace(go.Bar(\n    x=months,\n    y=[20, 14, 25, 16, 18, 22, 19, 15, 12, 16, 14, 17],\n    name='Primary Product',\n    marker_color='indianred'\n))\nfig.add_trace(go.Bar(\n    x=months,\n    y=[19, 14, 22, 14, 16, 19, 15, 14, 10, 12, 12, 16],\n    name='Secondary Product',\n    marker_color='lightsalmon'\n))\n\n# Here we modify the tickangle of the xaxis, resulting in rotated labels.\nfig.update_layout(barmode='group', xaxis_tickangle=-45)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"13\"></a>\n<font color=\"purple\" size=+2.5><b>13.Graph Objects customization of colors</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"colors = ['mediumorchid',] * 5\ncolors[1] = 'crimson'\n\nfig = go.Figure(data=[go.Bar(\n    x=['Feature A', 'Feature B', 'Feature C',\n       'Feature D', 'Feature E'],\n    y=[20, 14, 23, 25, 22],\n    marker_color=colors # marker color can be a single color value or an iterable\n)])\nfig.update_layout(title_text='Customize a each and every color')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure(data=[go.Bar(\n    x=[1, 2, 3, 5.5, 10],\n    y=[10, 8, 6, 4, 2],\n    width=[0.8, 0.8, 0.8, 3.5, 4],\n    marker_color=\"mediumseagreen\"# customize width here\n)])\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"14\"></a>\n<font color=\"purple\" size=+2.5><b>14.Relative mode Bar Chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"x = [1, 2, 3, 4]\n\nfig = go.Figure()\nfig.add_trace(go.Bar(x=x, y=[1, 4, 9, 16]))\nfig.add_trace(go.Bar(x=x, y=[6, -8, -4.5, 8]))\nfig.add_trace(go.Bar(x=x, y=[-15, -3, 4.5, -8]))\nfig.add_trace(go.Bar(x=x, y=[-1, 3, -3, -4]))\n\nfig.update_layout(barmode='relative', title_text='Relative Barmode')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"15\"></a>\n<font color=\"purple\" size=+2.5><b>15.Category Ascending order or descending order</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"x=['b', 'a', 'c', 'd']\nfig = go.Figure(go.Bar(x=x, y=[2,5,1,9], name='Montreal',marker_color=\"goldenrod\"))\nfig.add_trace(go.Bar(x=x, y=[1, 4, 9, 16], name='Ottawa'))\nfig.add_trace(go.Bar(x=x, y=[6, 8, 4.5, 8], name='Toronto'))\n\nfig.update_layout(barmode='stack', xaxis={'categoryorder':'category ascending'})\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x=['b', 'a', 'c', 'd']\nfig = go.Figure(go.Bar(x=x, y=[2,5,1,9], name='Montreal',marker_color=\"goldenrod\"))\nfig.add_trace(go.Bar(x=x, y=[1, 4, 9, 16], name='Ottawa'))\nfig.add_trace(go.Bar(x=x, y=[6, 8, 4.5, 8], name='Toronto'))\n\nfig.update_layout(barmode='stack', xaxis={'categoryorder':'total descending'})\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x = [\n    [\"BB+\", \"BB+\", \"BB+\", \"BB\", \"BB\", \"BB\"],\n    [16, 17, 18, 16, 17, 18,]\n]\nfig = go.Figure()\nfig.add_bar(x=df[\"Country\"],y=df[\"Sales Channel\"])\nfig.add_bar(x=df[\"Country\"],y=df[\"Sales Channel\"])\nfig.update_layout(barmode=\"stack\")\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"16\"></a>\n<font color=\"purple\" size=+2.5><b>16.Horizontal Stacked bar chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.bar(df,x=\"Total Profit\",y=\"Region\",orientation='h',color=\"Country\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"17\"></a>\n<font color=\"purple\" size=+2.5><b>17.Horizontal bar chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure(go.Bar(\n            x=[20, 14, 23],\n            y=['giraffes', 'orangutans', 'monkeys'],\n            orientation='h'))\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"18\"></a>\n<font color=\"purple\" size=+2.5><b>18.Basic Pie chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.pie(df,values=\"Total Profit\",names=df[\"Country\"])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"19\"></a>\n<font color=\"purple\" size=+2.5><b>19.Pie chart - Setting in bulit colors</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.pie(df,names=\"Country\",values=\"Total Profit\",color_discrete_sequence=px.colors.sequential.Blugrn_r)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df[\"Region\"].unique()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"20\"></a>\n<font color=\"purple\" size=+2.5><b>20.Pie chart - Repeated Labels</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.pie(df,names=df[\"Region\"],values=df[\"Total Cost\"],color_discrete_map={'Sub-Sarahan':'lightcyan',\n                                 'Europe':'cyan',\n                                 'Asia':'royalblue',\n                                 'North America':'darkblue',\n                                  'Middle East and North Africa':'green',\n                                'Central America and the Caribbean':\"yellow\",\n                                 'Australia and Oceania':'violet'}) \nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"21\"></a>\n<font color=\"purple\" size=+2.5><b>21.Customization of pie Chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.pie(df,names=df[\"Region\"],values=df[\"Total Cost\"],color_discrete_map={'Sub-Sarahan':'lightcyan',\n                                 'Europe':'cyan',\n                                 'Asia':'royalblue',\n                                 'North America':'darkblue',\n                                  'Middle East and North Africa':'green',\n                                'Central America and the Caribbean':\"yellow\",\n                                 'Australia and Oceania':'violet'},labels={'Region':'Region'}) \nfig.update_traces(textposition=\"inside\",textinfo='percent+label') \nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']\nvalues = [4500, 2500, 1053, 500]\n\nfig = go.Figure(data=[go.Pie(labels=labels, values=values)])\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"22\"></a>\n<font color=\"purple\" size=+2.5><b>22. Donut Chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.pie(df,names=\"Country\",values=\"Total Profit\",color_discrete_sequence=px.colors.sequential.Blugrn_r,hole=0.3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"23\"></a>\n<font color=\"purple\" size=+2.5><b>23.Pulling Sectors from The Center</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']\nvalues = [4500, 2500, 1053, 500]\n\nfig = go.Figure(data=[go.Pie(labels=labels, values=values,pull=[0,0,0.3,0.1])])\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Tables "},{"metadata":{},"cell_type":"markdown","source":"<a id=\"24\"></a>\n<font color=\"purple\" size=+2.5><b>24.Creation of table</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure(data=[go.Table(header=dict(values=['A Scores', 'B Scores']),\n                 cells=dict(values=[[100, 90, 80, 90], [95, 85, 75, 95]]))\n                     ])\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.columns[0:2]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"25\"></a>\n<font color=\"purple\" size=+2.5><b>25.Setting colors for table </b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure(data=[go.Table(header=dict(values=df.columns[0:2],\n                fill_color='lightskyblue',),\n                 cells=dict(values=[df.Region,df.Country], \n                            fill_color='lavender',\n                            align='left'))\n                     ])\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"26\"></a>\n<font color=\"purple\" size=+2.5><b>26.Figure Factory table</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"table = ff.create_table(df.iloc[:,0:4],colorscale='sunsetdark')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"table","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"27\"></a>\n<font color=\"purple\" size=+2.5><b>27.Tree map</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.treemap(df,path=[\"Region\",\"Country\",\"Sales Channel\"])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"28\"></a>\n<font color=\"purple\" size=+2.5><b>28.Suburst chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"df5 = px.data.tips()\nfig = px.sunburst(df5, path=['sex','day','time'], values='total_bill',color=\"time\",color_discrete_map={'(?)':'black', 'Lunch':'gold', 'Dinner':'darkblue'})\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"29\"></a>\n<font color=\"purple\" size=+2.5><b>29.Scatter webgl plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"N = 100000\n\ndf2 = pd.DataFrame(dict(x=np.random.randn(N),\n                       y=np.random.randn(N)))\n\nfig = px.scatter(df2, x=\"x\", y=\"y\", render_mode='webgl')\n\nfig.update_traces(marker_line=dict(width=1, color='DarkSlateGray'))\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"30\"></a>\n<font color=\"purple\" size=+2.5><b>30.Box Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.box(df,y=\"Total Cost\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"31\"></a>\n<font color=\"purple\" size=+2.5><b>31.Box Plot - Specified Colors</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.box(df,x=\"Sales Channel\",y=\"Total Cost\",color_discrete_sequence=px.colors.sequential.Blues_r)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"32\"></a>\n<font color=\"purple\" size=+2.5><b>32.Displaying data under box plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.box(df,x=\"Sales Channel\",y=\"Total Cost\",points=\"all\",color_discrete_sequence=px.colors.sequential.Blackbody)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"33\"></a>\n<font color=\"purple\" size=+2.5><b>33.Styled Box Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.box(df,x=\"Sales Channel\",y=\"Total Cost\",points=\"all\",notched=True,color_discrete_sequence=px.colors.sequential.Agsunset)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"34\"></a>\n<font color=\"purple\" size=+2.5><b>34.Strip Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.strip(df,x=\"Sales Channel\",y=\"Total Cost\",)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df3 = pd.read_csv(\"../input/stroke-prediction-dataset/healthcare-dataset-stroke-data.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df3.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"35\"></a>\n<font color=\"purple\" size=+2.5><b>35.Histogram</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.histogram(df3,x=\"avg_glucose_level\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"36\"></a>\n<font color=\"purple\" size=+2.5><b>36.Histogram - Specified Bins</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.histogram(df3,x=\"avg_glucose_level\",nbins=20)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"37\"></a>\n<font color=\"purple\" size=+2.5><b>37.Several histograms  for the different values of one column</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.histogram(df3,x=\"avg_glucose_level\",color=\"gender\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"38\"></a>\n<font color=\"purple\" size=+2.5><b>38.Histogram - Rug Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.histogram(df3,x=\"avg_glucose_level\",color=\"gender\",marginal='rug')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"39\"></a>\n<font color=\"purple\" size=+2.5><b>39.Histogram - Horizontal</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.histogram(df3,y=\"avg_glucose_level\",color=\"gender\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = go.Figure()\nfig.add_trace(go.Histogram(x=df3[\"avg_glucose_level\"]))\nfig.add_trace(go.Histogram(x=df3[\"bmi\"]))\n\n# The two histograms are drawn on top of another\nfig.update_layout(barmode='stack')\nfig.show()\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"40\"></a>\n<font color=\"purple\" size=+2.5><b>40.Cummulative Histogram</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.histogram(df3,x=df3[\"avg_glucose_level\"],cumulative=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df2 = sns.load_dataset(\"tips\") \ndf2.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"41\"></a>\n<font color=\"purple\" size=+2.5><b>41.Violin Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.violin(df2,y=\"tip\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"42\"></a>\n<font color=\"purple\" size=+2.5><b>42.Violin with box Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.violin(df2,y=\"tip\",points=\"all\",box=True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"43\"></a>\n<font color=\"purple\" size=+2.5><b>43.Displaying data under Violin Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.violin(df2, y = \"tip\", x=\"time\",box=True,points=\"all\",hover_data=df2.columns)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"44\"></a>\n<font color=\"purple\" size=+2.5><b>44.Overlay Violin Plot</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.violin(df2,y=\"tip\",points=\"all\",violinmode=\"overlay\",color=\"sex\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"45\"></a>\n<font color=\"purple\" size=+2.5><b>45.2d density heat map</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.density_heatmap(df,x=\"Total Cost\",y=\"Total Profit\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y = df.groupby(\"Region\")[\"Total Cost\"].sum()[0:].values\ny","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"46\"></a>\n<font color=\"purple\" size=+2.5><b>46.Funnel Chart</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.funnel(df,y=df[\"Region\"].unique(),x=y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df5  = pd.read_csv(\"../input/istanbul-stock-exchange/istanbul_stock_exchange.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df5.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"47\"></a>\n<font color=\"purple\" size=+2.5><b>47.Time Series data</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"px.line(df5,x=\"date\",y=\"EM\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"48\"></a>\n<font color=\"purple\" size=+2.5><b>48.Time Series - Range Slider</b></font>\n\n<a href=\"#top\" class=\"btn btn-primary btn-sm\" role=\"button\" aria-pressed=\"true\" style=\"color:white\" data-toggle=\"popover\" title=\"go to Colors\">Go to TOC</a>"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(df5,x=\"date\",y=\"EM\") \nfig.update_xaxes(rangeslider_visible=True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* * * ![](http://)![](http://)![](http://)![](http://)![](http://)![](http://)![](http://)![](http://)![](http://)![](http://)"},{"metadata":{},"cell_type":"markdown","source":"> > > > "},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}