{"id":3115,"date":"2020-02-08T08:32:44","date_gmt":"2020-02-08T08:32:44","guid":{"rendered":"https:\/\/www.askpython.com\/?p=3115"},"modified":"2023-02-16T19:57:16","modified_gmt":"2023-02-16T19:57:16","slug":"python-plotly-tutorial","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python-modules\/python-plotly-tutorial","title":{"rendered":"Python Plotly Tutorial"},"content":{"rendered":"\n<p>Python <code>Plotly library<\/code> serves the purpose of <strong>Data Visualization<\/strong>. It helps in creating interactive, best-quality graphs online and can save them offline as well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Need for Plotly in Python<\/h2>\n\n\n\n<p>Plotly is useful in the field of statistical analysis, data visualization, etc. The outcome of the analysis and predictions can be presented in vivid forms using Plotly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting started with Python Plotly<\/h2>\n\n\n\n<p>In order to utilize the Plotly library, we first need to install it using the <code>pip<\/code> command.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installation<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npip install plotly==4.5.0\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1387\" height=\"302\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Installation-of-Plotly.png\" alt=\"Installation Of Plotly\" class=\"wp-image-3117\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Installation-of-Plotly.png 1387w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Installation-of-Plotly-300x65.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Installation-of-Plotly-1024x223.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Installation-of-Plotly-768x167.png 768w\" sizes=\"auto, (max-width: 1387px) 100vw, 1387px\" \/><figcaption>Installation Of Plotly<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Charts in Python Plotly<\/h2>\n\n\n\n<p>Let&#8217;s dive into the functionalities served by the Plotly library of Python. This section covers some of the Basic Plotting techniques to serve the purpose of Data Visualization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Scatter plot<\/h3>\n\n\n\n<p>As the name suggests, it represents the data in a scattered format.<\/p>\n\n\n\n<p>We have used <a href=\"https:\/\/www.askpython.com\/python-modules\/numpy\/python-numpy-arrays\" class=\"rank-math-link\">NumPy<\/a> to generate random values to be passed as input to the graph.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly\nimport plotly.graph_objs as G\n\n\nimport numpy\n\nnum = 15\nx = numpy.random.randn(num)\ny = numpy.random.randn(num)\n\n# Create a trace\nfollow = G.Scatter(\n    x = random_x,\n    y = random_y,\n    mode = &#039;markers&#039;\n)\noutput = &#x5B;follow]\n\n\nplotly.offline.plot(output, filename=&#039;basic-scatter.html&#039;)\n\n<\/pre><\/div>\n\n\n<p>The<code> plotly.graph<\/code> contains <code>JSON object<\/code> which is a <code>dict <\/code>like structure. By updating values of few keywords of this object, vivid kinds of graphs can be plotted.<\/p>\n\n\n\n<p>In the above snippet, plotly.graph&#8217;s JSON object is represented as G. Further,  we have used <code>NumPy<\/code> to generate random values for the sake of providing input and plotting of data.<\/p>\n\n\n\n<p><code>object.Scatter()<\/code> is used to provide dimensional values i.e. create a trace and is useful to set other attributes that we feel like adding to the graph. <\/p>\n\n\n\n<p>The <strong>x and y parameters<\/strong> contain the values to be plotted on the x and y-axis.<\/p>\n\n\n\n<p>The parameter<code> mode<\/code> determines <strong>the mode of representation<\/strong> of Scatter Plot. It can have any of the following values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>lines <\/li><li>markers <\/li><li>lines+markers <\/li><li>lines+markers+text<\/li><li>none<\/li><\/ul>\n\n\n\n<p><code>lines<\/code> plot values through lines as a drawing mode.<\/p>\n\n\n\n<p><code>markers<\/code> would plot value by marking the un-segregated data as points. <\/p>\n\n\n\n<p><code>plotly.offline<\/code> enables the programmer to plot the values in an offline manner and save it. It accepts a <strong>filename<\/strong> as an argument which is the .html page that would display the offline plotting of the data.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Scatter_Plotly.png\" alt=\"Scatter Plotly\" class=\"wp-image-3119\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Scatter_Plotly.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Scatter_Plotly-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Scatter Plotly<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. Line-Scatter plot<\/h3>\n\n\n\n<p>In this type of plotting, a combination of line and scattering fashion is used to represent the data.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly\nimport plotly.graph_objs as G\n\n\nimport numpy as p\n\nN = 20\nx = p.linspace(0, 1, N)\none_y=p.random.randn(N)+10\ntwo_y=p.random.randn(N)\nthree_y=p.random.randn(N)-10\n\n# Create traces\nplot0 = G.Scatter(\n    x = x,\n    y = one_y,\n    mode = &#039;markers&#039;\n)\n\nplot1 = G.Scatter(\n    x = x,\n    y = two_y,\n    mode = &#039;lines+markers&#039;\n    \n)\n\nplot2 = G.Scatter(\n    x = x,\n    y = three_y,\n    mode = &#039;lines&#039;\n)\n\noutput = &#x5B;plot0, plot1, plot2]\nplotly.offline.plot(output, filename=&#039;line-scatter.html&#039;)\n\n<\/pre><\/div>\n\n\n<p>In the above snippet of code, we have used <code>numpy.linespace()<\/code> function to generate evenly spaced values for the x dimension.<\/p>\n\n\n\n<p>Further, we have used <code>numpy.random()<\/code> function to generate random values for three different traces through y-axis. <\/p>\n\n\n\n<p>As seen above, we have passed different values to the parameter mode, representing the type of drawing fashion. <code>line+markers<\/code> represents the values and plots them with a combination of lines and marker dots.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Line-Scatter-plot.png\" alt=\"Line Scatter Plot\" class=\"wp-image-3120\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Line-Scatter-plot.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Line-Scatter-plot-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Line Scatter Plot<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. Bubble Scatter Plot<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.graph_objects as G\n\nimg = G.Figure(data=G.Scatter(\n    x=&#x5B;10, 20, 30, 40],\n    y=&#x5B;5, 10, 15, 20],\n    mode=&#039;markers&#039;,\n    marker=dict(size=&#x5B;10,20,30,40],\n                color=&#x5B;1, 2, 3, 4])\n))\n\nimg.show()\n<\/pre><\/div>\n\n\n<p><code>marker<\/code> is a <a href=\"https:\/\/www.askpython.com\/python\/dictionary\/python-dictionary-dict-tutorial\" class=\"rank-math-link\">dict<\/a> that sets the symbol for representing the data. <code>size<\/code> is used to pass the dimensions to the drawing symbol and <code>color<\/code> is used to set values to add color to those drawing symbols.<\/p>\n\n\n\n<p>The <code>plotly.Figure()<\/code> function basically contains data and the drawing layout and it combines both of these values to create a figure. <strong>The data and layout values can be represented as graph objects or dict.<\/strong><\/p>\n\n\n\n<p>The <code>plotly.show()<\/code> function is used to plot the figure along with its layout design.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Bubble_Scatter-Plot.png\" alt=\"Bubble Scatter Plot\" class=\"wp-image-3122\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Bubble_Scatter-Plot.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Bubble_Scatter-Plot-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Bubble Scatter Plot<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Statistical Style Charts<\/h2>\n\n\n\n<p>These kinds of charts are helpful in displaying the data in a much simplified manner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Box Plot<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.graph_objects as G\nimport numpy\n\na = numpy.random.randn(100) - 10\nb = numpy.random.randn(100) + 10\n\noutput = G.Figure()\noutput.add_trace(G.Box(y=a))\noutput.add_trace(G.Box(y=b))\n\noutput.show()\n<\/pre><\/div>\n\n\n<p><code>plotly.add_trace()<\/code> function is used to update the graph by adding traces to the x and y dimensions. It accepts a graph object to be traced as a parameter i.e. <code>G.Scatter<\/code>, <code>G.Box<\/code>, etc.<\/p>\n\n\n\n<p><code>plotly.graph.object.Box()<\/code> basically sets the tracing values to the particular dimension.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Box-plot.png\" alt=\"Box Plot\" class=\"wp-image-3129\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Box-plot.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Box-plot-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Box Plot<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. Histogram<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.graph_objects as G\n\nimport numpy as N\n\nx = N.random.randn(100)\n\noutput = G.Figure(data=&#x5B;G.Histogram(x=x)])\noutput.show()\n\n<\/pre><\/div>\n\n\n<p><code>plotly.graph.object.Histogram()<\/code> is used to construct a Histogram. <strong>x=x specifies the growth of the histogram on y-axis<\/strong> and vice versa.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Histogram.png\" alt=\"Histogram\" class=\"wp-image-3130\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Histogram.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Histogram-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Histogram<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. DistPlots<\/h3>\n\n\n\n<p>The Distplot helps us plot un-distributed data and enables us to observe or inspect the values through the line plot.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.figure_factory as ff\nimport numpy as N\n\n\nx = N.random.randn(500)\ndata = &#x5B;x]\nlabel = &#x5B;&#039;DISTPLOT&#039;] \n\noutput = ff.create_distplot(data, label)\noutput.show()\n<\/pre><\/div>\n\n\n<p><strong>Python&#8217;s API<\/strong> contains <code>figure factory module<\/code> to plot the data in a simplified manner. <\/p>\n\n\n\n<p><code>figure_factory.distplot()<\/code> plots the data as represents it as a <strong>combination of the histogram, normal curve<\/strong>, etc. The <code>label<\/code> parameter is used to set a text label to the graph.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/DistPlot.png\" alt=\"DistPlot\" class=\"wp-image-3132\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/DistPlot.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/DistPlot-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>DistPlot<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Scientific Charts<\/h2>\n\n\n\n<p>These charts help in the analysis of scientific values or data from a wider perspective.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Counter Plots<\/h3>\n\n\n\n<p>Counter Plots are basically used in the scientific analysis of the huge amount of data together.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.graph_objects as G\nfrom plotly.subplots import make_subplots\n\n\nz =   &#x5B;&#x5B;2, 4, 7, 12, 13, 14, 15, 16],\n       &#x5B;3, 1, 6, 11, 12, 13, 16, 17],\n       &#x5B;4, 2, 7, 7, 11, 14, 17, 18],\n       &#x5B;5, 3, 8, 8, 13, 15, 18, 19],\n       &#x5B;7, 4, 10, 9, 16, 18, 20, 19],\n       &#x5B;9, 10, 5, 27, 23, 21, 21, 21],\n       &#x5B;11, 14, 17, 26, 25, 24, 23, 22]]\n\nout = make_subplots(rows=1, cols=1)\n\nout.add_trace(G.Contour(z=z))\n\nout.show()\n<\/pre><\/div>\n\n\n<p><code>plotly.subplots<\/code> module enables the creation of numerous subplots of the data using the <code>make_subplots()<\/code> function.<\/p>\n\n\n\n<p>The <code>plotly.graph.objects.Contour() <\/code>is used to create contour lines from the input array provided.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Counter-Plots.png\" alt=\"Counter Plots\" class=\"wp-image-3134\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Counter-Plots.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Counter-Plots-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Counter Plots<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. Heatmaps in Plotly<\/h3>\n\n\n\n<p>In Heatmap Plotting, each value passed to the input is represented as a pixel. On similar lines, Heatmaps too can be used to enhance the analysis of scientific values and research.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.graph_objects as G\n\nout = G.Figure(data=G.Heatmap(\n                    z=&#x5B;&#x5B;10, 20, 30],\n                      &#x5B;20, 30, 40],\n                      &#x5B;40, 50, 60]]))\nout.show()\n<\/pre><\/div>\n\n\n<p>The <code>plotly.graph.obejct.Heatmap() <\/code>function basically represents each value of the input data as Heatmap pixel.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Heatmaps.png\" alt=\"Heatmaps\" class=\"wp-image-3135\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Heatmaps.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Heatmaps-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Heatmaps<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Financial Plots<\/h2>\n\n\n\n<p>These can be considered as one of the most complex charts to form and depict the real-time analysis in a better manner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Time-Series Chart<\/h3>\n\n\n\n<p>In the below snippet of code, we have used <a href=\"https:\/\/www.askpython.com\/python-modules\/pandas\/python-pandas-module-tutorial\" class=\"rank-math-link\">Pandas Module<\/a> to read the CSV file and then have plotted the time-series chart for the same.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.express as px\nimport pandas as pd\n\ndf = pd.read_csv(&#039;C:\\\\Users\\\\HP\\\\Desktop\\\\output11.csv&#039;)\n\nfig = px.line(df, x=&#039;Marks&#039;, y=&#039;Sr no&#039;)\nfig.show()\n<\/pre><\/div>\n\n\n<p>The file I&#8217;ve used is a simple file with two columns, serial number (sr no) and marks. The data is plotted automatically based on which axis uses which column of data. You can try the same with any two-column data CSV file.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"989\" height=\"438\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/csv-file.png\" alt=\"Csv File\" class=\"wp-image-3168\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/csv-file.png 989w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/csv-file-300x133.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/csv-file-768x340.png 768w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><figcaption>Csv File Snapshot<\/figcaption><\/figure><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Time-Series.png\" alt=\"Time Series\" class=\"wp-image-3137\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Time-Series.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Time-Series-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Time Series<\/figcaption><\/figure><\/div>\n\n\n\n<p><strong>Alternatively, you can simply provide the data in the form of two lists as shown below<\/strong>. I&#8217;m providing some random values to show how the line charts form.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.express as px\nsr = &#x5B;1,2,3,4,5,6]\nmarks = &#x5B;20, 10, 50, 30, 100, 75]\n\nfig = px.line(x=marks, y=sr)\nfig.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"479\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/graph-plotly-1024x479.png\" alt=\"Graph Plotly\" class=\"wp-image-3167\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/graph-plotly-1024x479.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/graph-plotly-300x140.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/graph-plotly-768x359.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/graph-plotly-1536x718.png 1536w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/graph-plotly.png 1773w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Plotly Graph<\/figcaption><\/figure><\/div>\n\n\n\n<p>The <code>plotly.express package<\/code> is used to provide high quality and simplified graphs overall.<\/p>\n\n\n\n<p><code>plotly.express.line()<\/code> function is used to plot a line according to the provided values and labels to the x and y dimensions. <\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. Funnel Charts<\/h3>\n\n\n\n<p>Funnel charts enable us to represent the data in the different forms of stages resembling the business development process.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.express as p\ndata = dict(\n    num=&#x5B;25, 50, 75, 100],\n    work=&#x5B;&quot;Requirement Analysis&quot;, &quot;Design&quot;, &quot;Modelling and Construction&quot;, &quot;Testing and Deployment&quot;])\nout = p.funnel(data, x=&#039;num&#039;, y=&#039;work&#039;)\nout.show()\n<\/pre><\/div>\n\n\n<p><code>express.funnel()<\/code> function represents every row of the input DataFrame as a stage of the funnel. Here, the input <strong>num<\/strong> and <strong>work<\/strong> are represented in the form of funnel structure.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Funnel-Charts.png\" alt=\"Funnel Charts\" class=\"wp-image-3143\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Funnel-Charts.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/Funnel-Charts-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>Funnel Charts<\/figcaption><\/figure><\/div>\n\n\n\n<p>As seen above, the chart depicts the stages of the development and the values associated with it.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3-D Charts<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport plotly.graph_objects as G\nimport numpy as N\n\n\nn = 100\n\nfigure = G.Figure(data=&#x5B;G.Mesh3d(x=(55*N.random.randn(n)),\n                   y=(50*N.random.randn(n)),\n                   z=(25*N.random.randn(n)),\n                   opacity=0.8,\n                   color=&#039;rgba(244,22,100,0.6)&#039;\n                  )])\n\n\n\nfigure.show()\n<\/pre><\/div>\n\n\n<p><code>plotly.graph.object.Mesh3d()<\/code> represents the data as a 3-D drawing structure having vertices x, y, z.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"450\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/3-D-Plot.png\" alt=\"3 D Plot\" class=\"wp-image-3163\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/3-D-Plot.png 700w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/3-D-Plot-300x193.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption>3 D Plot<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Thus, in this article, we have understood the functions served by Python&#8217;s Plotly library.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Python Plotly library<\/li><li><a href=\"https:\/\/plotly.com\/python\/\" class=\"rank-math-link\" target=\"_blank\" rel=\"noopener\">Plotly Documentation<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Python Plotly library serves the purpose of Data Visualization. It helps in creating interactive, best-quality graphs online and can save them offline as well. Need for Plotly in Python Plotly is useful in the field of statistical analysis, data visualization, etc. The outcome of the analysis and predictions can be presented in vivid forms using [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":3151,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3115","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-modules"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/3115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=3115"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/3115\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/3151"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=3115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=3115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=3115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}