{"id":3283,"date":"2020-05-09T09:24:27","date_gmt":"2020-05-09T09:24:27","guid":{"rendered":"https:\/\/www.staging6.machinelearningplus.com\/?p=3283"},"modified":"2021-05-27T09:12:35","modified_gmt":"2021-05-27T09:12:35","slug":"waterfall-plot-in-python","status":"publish","type":"page","link":"https:\/\/machinelearningplus.com\/waterfall-plot-in-python\/","title":{"rendered":"Waterfall Plot in Python"},"content":{"rendered":"<p><em>Waterfall chart is a 2D plot that is used to understand the effects of adding positive or negative values over time or over multiple steps or a variable. Waterfall chart is frequently used in financial analysis to understand the gain and loss contributions of multiple factors over a particular asset.<\/em><\/p>\n<h2 id=\"contents\">Contents<\/h2>\n<ol>\n<li>Introduction<\/li>\n<li>Simple Waterfall Plot<\/li>\n<li>Varying parameters in Waterfall Plot<\/li>\n<li>Analyzing a waterfall plot<\/li>\n<li>Interpreting feature importance<\/li>\n<\/ol>\n<h2 id=\"introduction\">Introduction<\/h2>\n<p>Waterfall chart is a 2-dimensional plot that is used to <strong>understanding the cumulative effects of sequentially added positive or negative values<\/strong> for a given variable.<\/p>\n<p>This will help you in knowing about how an initial value is increased and decreased over time or over a series of intermediate steps.<br \/>\nThe cumulative effects can be either time based or category based.<\/p>\n<p>This type of plot is <strong>commonly used in financial analysis to understand how a particular value goes through gains and losses over time<\/strong>.<\/p>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/800px-Waterfall-chart-min.jpg\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/800px-Waterfall-chart-min.jpg\" alt=\"\" width=\"800\" height=\"545\" class=\"alignnone size-full wp-image-3285\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/800px-Waterfall-chart-min.jpg 800w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/800px-Waterfall-chart-min-300x204.jpg 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/800px-Waterfall-chart-min-768x523.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>Notice that only some of the columns (generally initial and final column) are shown fully and the other columns in between are shown as floating columns( they only show the increase or decrease in the value).<\/p>\n<p>We will look into how to draw a waterfall chart like the one shown above.<\/p>\n<p>First, you need to install the <code>waterfallcharts<\/code> library to use the <code>waterfall_chart<\/code>.<\/p>\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># Install<\/span>\n!pip <span class=\"hljs-keyword\">install<\/span> waterfallcharts\n<\/code><\/pre>\n<p>Then I am going to import all the required libraries that I will be using in this article.<\/p>\n<pre><code class=\"lang-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> numpy <span class=\"hljs-keyword\">as<\/span> np\n<span class=\"hljs-keyword\">import<\/span> waterfall_chart\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\n%matplotlib inline\nplt.rcParams.update({<span class=\"hljs-string\">'figure.figsize'<\/span>:(<span class=\"hljs-number\">7.5<\/span>,<span class=\"hljs-number\">5<\/span>), <span class=\"hljs-string\">'figure.dpi'<\/span>:<span class=\"hljs-number\">100<\/span>})\n<\/code><\/pre>\n<p>Now, let&#8217;s look at how to plot a simple waterfall chart in Python.<\/p>\n<h2 id=\"simple-waterfall-plot\">Simple Waterfall Plot<\/h2>\n<p>Use the <code>plot()<\/code> function in <code>waterfall_chart<\/code> library to generate a waterfall chart. Values of x and y-axis should be passed as parameters into the function. Let&#8217;s try to visualize a simple cash flow chart for whole year months.<\/p>\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># plotting a simple waterfall chart<\/span>\n<span class=\"hljs-keyword\">import<\/span> waterfall_chart\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\na = [<span class=\"hljs-string\">'jan'<\/span>,<span class=\"hljs-string\">'feb'<\/span>,<span class=\"hljs-string\">'mar'<\/span>,<span class=\"hljs-string\">'apr'<\/span>,<span class=\"hljs-string\">'may'<\/span>,<span class=\"hljs-string\">'jun'<\/span>,<span class=\"hljs-string\">'jul'<\/span>,<span class=\"hljs-string\">'aug'<\/span>,<span class=\"hljs-string\">'sep'<\/span>,<span class=\"hljs-string\">'oct'<\/span>,<span class=\"hljs-string\">'nov'<\/span>,<span class=\"hljs-string\">'dec'<\/span>]\nb = [<span class=\"hljs-number\">1000<\/span>,<span class=\"hljs-number\">-300<\/span>,<span class=\"hljs-number\">400<\/span>,<span class=\"hljs-number\">-100<\/span>,<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">-700<\/span>,<span class=\"hljs-number\">400<\/span>,<span class=\"hljs-number\">-300<\/span>,<span class=\"hljs-number\">500<\/span>,<span class=\"hljs-number\">-700<\/span>,<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">50<\/span>]\nwaterfall_chart.plot(a, b);\n<\/code><\/pre>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_9_0-min.png\"><img decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_9_0-min.png\" alt=\"\" width=\"740\" height=\"490\" class=\"alignnone size-full wp-image-3286\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_9_0-min.png 740w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_9_0-min-300x199.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<p>You can see that it took the initial value and started adding and subtracting the values that I have passed and also calculated the final left out amount.<\/p>\n<p>The increasing values are shown in green color and the decreasing values are shown in red color.<\/p>\n<p>This plot is used extensively in the finance sector for checking their revenues.<\/p>\n<h2 id=\"varying-parameters-in-waterfall-plot\">Varying parameters in Waterfall plot<\/h2>\n<p>Set <code>sorted_value=True<\/code> inside the <code>plot()<\/code> function to sort the values based on the absolute value of every month.<\/p>\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># varying the sorted_value parameter<\/span>\n<span class=\"hljs-keyword\">import<\/span> waterfall_chart\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\na = [<span class=\"hljs-string\">'jan'<\/span>,<span class=\"hljs-string\">'feb'<\/span>,<span class=\"hljs-string\">'mar'<\/span>,<span class=\"hljs-string\">'apr'<\/span>,<span class=\"hljs-string\">'may'<\/span>,<span class=\"hljs-string\">'jun'<\/span>,<span class=\"hljs-string\">'jul'<\/span>,<span class=\"hljs-string\">'aug'<\/span>,<span class=\"hljs-string\">'sep'<\/span>,<span class=\"hljs-string\">'oct'<\/span>,<span class=\"hljs-string\">'nov'<\/span>,<span class=\"hljs-string\">'dec'<\/span>]\nb = [<span class=\"hljs-number\">1000<\/span>,<span class=\"hljs-number\">-300<\/span>,<span class=\"hljs-number\">400<\/span>,<span class=\"hljs-number\">-100<\/span>,<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">-700<\/span>,<span class=\"hljs-number\">400<\/span>,<span class=\"hljs-number\">-300<\/span>,<span class=\"hljs-number\">500<\/span>,<span class=\"hljs-number\">-700<\/span>,<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">50<\/span>]\nwaterfall_chart.plot(a, b,sorted_value=<span class=\"hljs-keyword\">True<\/span>)\n<\/code><\/pre>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_12_1-min.png\"><img decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_12_1-min.png\" alt=\"\" width=\"740\" height=\"490\" class=\"alignnone size-full wp-image-3287\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_12_1-min.png 740w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_12_1-min-300x199.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<p>As you can see the values are sorted based on their absolute values in descending order.<\/p>\n<p>Use the <code>net_label=\"\"<\/code> command to change the final column name which is set to default as net.<\/p>\n<p><code>rotation_value=90<\/code> can be used to rotate the x-axis names in vertical mode.<\/p>\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># varying the net_label parameter<\/span>\n<span class=\"hljs-keyword\">import<\/span> waterfall_chart\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\na = [<span class=\"hljs-string\">'jan'<\/span>,<span class=\"hljs-string\">'feb'<\/span>,<span class=\"hljs-string\">'mar'<\/span>,<span class=\"hljs-string\">'apr'<\/span>,<span class=\"hljs-string\">'may'<\/span>,<span class=\"hljs-string\">'jun'<\/span>,<span class=\"hljs-string\">'jul'<\/span>,<span class=\"hljs-string\">'aug'<\/span>,<span class=\"hljs-string\">'sep'<\/span>,<span class=\"hljs-string\">'oct'<\/span>,<span class=\"hljs-string\">'nov'<\/span>,<span class=\"hljs-string\">'dec'<\/span>]\nb = [<span class=\"hljs-number\">1000<\/span>,<span class=\"hljs-number\">-300<\/span>,<span class=\"hljs-number\">400<\/span>,<span class=\"hljs-number\">-100<\/span>,<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">-700<\/span>,<span class=\"hljs-number\">400<\/span>,<span class=\"hljs-number\">-300<\/span>,<span class=\"hljs-number\">500<\/span>,<span class=\"hljs-number\">-700<\/span>,<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">50<\/span>]\nwaterfall_chart.plot(a, b,sorted_value=<span class=\"hljs-keyword\">True<\/span>,net_label=<span class=\"hljs-string\">'LeftOver'<\/span>,rotation_value=<span class=\"hljs-number\">90<\/span>)\n<\/code><\/pre>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_14_1-min.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_14_1-min.png\" alt=\"\" width=\"740\" height=\"490\" class=\"alignnone size-full wp-image-3288\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_14_1-min.png 740w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_14_1-min-300x199.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<p>There is also another command <code>threshold<\/code> which groups all contributions under a certain threshold to as a separate &#8216;other&#8217; contribution.<\/p>\n<p>If you set the value of the threshold to be 0.5, then it will take only the first half of the dataset and show it in the graph. The other part will be shown in the other column.<\/p>\n<pre><code class=\"lang-python\"># <span class=\"hljs-keyword\">using<\/span> the threshold <span class=\"hljs-keyword\">parameter<\/span>\nimport <span class=\"hljs-comment\">waterfall_chart<\/span>\nimport <span class=\"hljs-comment\">matplotlib.pyplot as plt<\/span>\na <span class=\"hljs-comment\">= [<\/span><span class=\"hljs-comment\">'jan'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'feb'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'mar'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'apr'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'may'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'jun'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'jul'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'aug'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'sep'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'oct'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'nov'<\/span><span class=\"hljs-comment\">,<\/span><span class=\"hljs-comment\">'dec'<\/span><span class=\"hljs-comment\">]<\/span>\nb <span class=\"hljs-comment\">= [1000,-300,400,-100,100,-700,400,-300,500,-700,100,50]<\/span>\nwaterfall_chart.plot(a, b,sorted_value=True,net_label=<span class=\"hljs-string\">'LeftOver'<\/span>,rotation_value=90,threshold=0.5)\n<\/code><\/pre>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_16_1-min.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_16_1-min.png\" alt=\"\" width=\"740\" height=\"490\" class=\"alignnone size-full wp-image-3289\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_16_1-min.png 740w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_16_1-min-300x199.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<h2 id=\"analysing-a-waterfall-chart\">Analyzing a waterfall chart<\/h2>\n<p>A waterfall chart can be used for analytical purposes, especially for understanding the transition in the quantitative value of an entity that is subjected to increment or decrement.<\/p>\n<p>Let&#8217;s look at a waterfall chart containing yearly data with revenue from each quarter and try to get some insights.<br \/>\n<a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/Waterfall-min.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/Waterfall-min.png\" alt=\"\" width=\"384\" height=\"240\" class=\"alignnone size-full wp-image-3291\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/Waterfall-min.png 384w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/Waterfall-min-300x188.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/Waterfall-min-200x125.png 200w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/a><\/p>\n<p>The first column <code>initial<\/code> contains the value at the start of the year. Then for each quarter, you can see whether the amount has increased or not. During the midway of the year, you can see that the value has decreased to 400.<\/p>\n<p>Then during the next half, the value decreased in the 3rd quarter and increased in the 4th quarter leading to a total value of 425.<\/p>\n<p>Waterfall charts represent increasing values in green color and decreasing values in red color.<\/p>\n<p>Waterfall charts can also be used in various cases like <strong>inventory<\/strong> and performance analysis.<\/p>\n<h2 id=\"waterfall-chart-for-interpreting-feature-importance\">Waterfall Chart for Interpreting Feature Importance<\/h2>\n<p>I am going to be using the <code>heart<\/code> dataset from kaggle in which the main goal is to predict whether the person has got heart disease or not using the given features. I will be using <code>RandomForestClassifier<\/code> for modeling. Then the waterfall chart is used to visualize the importance of each variable.<\/p>\n<p>Download the dataset from the given link :<br \/>\n<a href=\"https:\/\/www.kaggle.com\/ronitf\/heart-disease-uci\/download\">https:\/\/www.kaggle.com\/ronitf\/heart-disease-uci\/download<\/a><\/p>\n<p>Now, let&#8217;s look at the code.<\/p>\n<pre><code class=\"lang-python\"># importing the required files and libarries\n<span class=\"hljs-keyword\">import<\/span> numpy <span class=\"hljs-keyword\">as<\/span> np\n<span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-title\">from<\/span> sklearn.model_selection <span class=\"hljs-keyword\">import<\/span> train_test_split\n<span class=\"hljs-title\">df<\/span>=pd.read_csv(<span class=\"hljs-string\">\"heart.csv\"<\/span>)\n<span class=\"hljs-title\">df<\/span>.head()\n<\/code><\/pre>\n<div><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/heart-dataset.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/heart-dataset.png\" alt=\"\" width=\"670\" height=\"166\" class=\"alignnone size-full wp-image-3292\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/heart-dataset.png 670w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/heart-dataset-300x74.png 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/a>\n<\/div>\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># Build Random forest model<\/span>\n<span class=\"hljs-comment\"># 1. splitting the dataset into test and train<\/span>\n<span class=\"hljs-attr\">y=df['target']<\/span>\ndf.drop('target',<span class=\"hljs-attr\">axis=1,inplace=True)<\/span>\nX_train,X_test,y_train,<span class=\"hljs-attr\">y_test=train_test_split(df,y)<\/span>\n\n<span class=\"hljs-comment\"># 2. creating the model<\/span>\nfrom sklearn.ensemble <span class=\"hljs-built_in\">import<\/span> RandomForestRegressor, RandomForestClassifier\n<span class=\"hljs-attr\">model<\/span> = RandomForestClassifier(<span class=\"hljs-attr\">n_estimators<\/span> = <span class=\"hljs-number\">150<\/span>, \n                               <span class=\"hljs-attr\">random_state<\/span> = <span class=\"hljs-number\">101<\/span>)\n\n<span class=\"hljs-comment\"># 3. fitting the model<\/span>\nmodel.fit(X_train,y_train)\n<\/code><\/pre>\n<pre><code>RandomForestClassifier(<span class=\"hljs-attr\">bootstrap=True,<\/span> <span class=\"hljs-attr\">ccp_alpha=0.0,<\/span> <span class=\"hljs-attr\">class_weight=None,<\/span>\n                       <span class=\"hljs-attr\">criterion='gini',<\/span> <span class=\"hljs-attr\">max_depth=None,<\/span> <span class=\"hljs-attr\">max_features='auto',<\/span>\n                       <span class=\"hljs-attr\">max_leaf_nodes=None,<\/span> <span class=\"hljs-attr\">max_samples=None,<\/span>\n                       <span class=\"hljs-attr\">min_impurity_decrease=0.0,<\/span> <span class=\"hljs-attr\">min_impurity_split=None,<\/span>\n                       <span class=\"hljs-attr\">min_samples_leaf=1,<\/span> <span class=\"hljs-attr\">min_samples_split=2,<\/span>\n                       <span class=\"hljs-attr\">min_weight_fraction_leaf=0.0,<\/span> <span class=\"hljs-attr\">n_estimators=150,<\/span>\n                       <span class=\"hljs-attr\">n_jobs=None,<\/span> <span class=\"hljs-attr\">oob_score=False,<\/span> <span class=\"hljs-attr\">random_state=101,<\/span>\n                       <span class=\"hljs-attr\">verbose=0,<\/span> <span class=\"hljs-attr\">warm_start=False)<\/span>\n<\/code><\/pre>\n<p>Let&#8217;s use <code>treeinterpreter<\/code> to interpret the importance of variables. So you need to install the library first.<\/p>\n<pre><code class=\"lang-python\">!pip <span class=\"hljs-keyword\">install<\/span> treeinterpreter # <span class=\"hljs-keyword\">for<\/span> installing the <span class=\"hljs-keyword\">first<\/span> <span class=\"hljs-keyword\">time<\/span>\n<span class=\"hljs-keyword\">from<\/span> treeinterpreter <span class=\"hljs-keyword\">import<\/span> treeinterpreter <span class=\"hljs-keyword\">as<\/span> ti\nrownames = X_test.values[<span class=\"hljs-keyword\">None<\/span>,<span class=\"hljs-number\">1<\/span>]\n<span class=\"hljs-keyword\">prediction<\/span>, bias, contributions = ti.predict(<span class=\"hljs-keyword\">model<\/span>, rownames)\ncontributions = [contributions[<span class=\"hljs-number\">0<\/span>][i][<span class=\"hljs-number\">0<\/span>] <span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">range<\/span>(<span class=\"hljs-keyword\">len<\/span>(contributions[<span class=\"hljs-number\">0<\/span>]))]\ncolnames = X_test.columns[<span class=\"hljs-number\">0<\/span>:].values\n<\/code><\/pre>\n<p>From the above output, you can use the column names and contributions to draw the <code>waterfall_chart<\/code>.<\/p>\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># waterfall chart<\/span>\n<span class=\"hljs-built_in\">import<\/span> waterfall_chart\n<span class=\"hljs-attr\">my_plot=waterfall_chart.plot(colnames,<\/span> contributions, <span class=\"hljs-attr\">rotation_value=90,<\/span> <span class=\"hljs-attr\">threshold=0.3,formatting='{:,.3f}')<\/span>\n<\/code><\/pre>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_25_0-min-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_25_0-min-1.png\" alt=\"\" width=\"740\" height=\"490\" class=\"alignnone size-full wp-image-3293\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_25_0-min-1.png 740w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/output_25_0-min-1-300x199.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<h2 id=\"recommended-posts\">Recommended Posts<\/h2>\n<ol>\n<li><a href=\"https:\/\/machinelearningplus.com\/plots\/matplotlib-pyplot\/\">Matplotlib Pyplot<\/a>\n<\/li>\n<li><a href=\"https:\/\/machinelearningplus.com\/plots\/top-50-matplotlib-visualizations-the-master-plots-python\/\">Top 50 Matplotlib Visualizations<\/a>\n<\/li>\n<li><a href=\"https:\/\/machinelearningplus.com\/plots\/matplotlib-tutorial-complete-guide-python-plot-examples\/\">Matplotlib Tutorial &#8211; A complete guide to Python Plot<\/a>\n<\/li>\n<\/ol>\n<p>This article was contributed by <a href=\"https:\/\/machinelearningplus.com\/venmani\/\" rel=\"noopener noreferrer\" target=\"_blank\">Venmani<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Waterfall chart is a 2D plot that is used to understand the effects of adding positive or negative values over time or over multiple steps or a variable. Waterfall chart is frequently used in financial analysis to understand the gain and loss contributions of multiple factors over a particular asset. Contents Introduction Simple Waterfall Plot [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":3462,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-3283","page","type-page","status-publish","has-post-thumbnail","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Waterfall Plot in Python - machinelearningplus<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/localhost:8080\/waterfall-plot-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Waterfall Plot in Python - machinelearningplus\" \/>\n<meta property=\"og:description\" content=\"Waterfall chart is a 2D plot that is used to understand the effects of adding positive or negative values over time or over multiple steps or a variable. Waterfall chart is frequently used in financial analysis to understand the gain and loss contributions of multiple factors over a particular asset. Contents Introduction Simple Waterfall Plot [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/localhost:8080\/waterfall-plot-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"machinelearningplus\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-27T09:12:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/localhost:8080\/wp-content\/uploads\/2020\/05\/waterfall_plot-min.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"622\" \/>\n\t<meta property=\"og:image:height\" content=\"338\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/waterfall-plot-in-python\\\/\",\"url\":\"https:\\\/\\\/localhost:8080\\\/waterfall-plot-in-python\\\/\",\"name\":\"Waterfall Plot in Python - machinelearningplus\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/waterfall-plot-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/waterfall-plot-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/waterfall_plot-min.jpg\",\"datePublished\":\"2020-05-09T09:24:27+00:00\",\"dateModified\":\"2021-05-27T09:12:35+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/localhost:8080\\\/waterfall-plot-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/waterfall-plot-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/waterfall_plot-min.jpg\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/waterfall_plot-min.jpg\",\"width\":622,\"height\":338,\"caption\":\"Waterfall Plot in Python\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"name\":\"machinelearningplus\",\"description\":\"Learn Data Science (AI \\\/ ML) Online\",\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/machinelearningplus.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\",\"name\":\"machinelearningplus\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"width\":348,\"height\":36,\"caption\":\"machinelearningplus\"},\"image\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Waterfall Plot in Python - machinelearningplus","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/localhost:8080\/waterfall-plot-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Waterfall Plot in Python - machinelearningplus","og_description":"Waterfall chart is a 2D plot that is used to understand the effects of adding positive or negative values over time or over multiple steps or a variable. Waterfall chart is frequently used in financial analysis to understand the gain and loss contributions of multiple factors over a particular asset. Contents Introduction Simple Waterfall Plot [&hellip;]","og_url":"https:\/\/localhost:8080\/waterfall-plot-in-python\/","og_site_name":"machinelearningplus","article_modified_time":"2021-05-27T09:12:35+00:00","og_image":[{"width":622,"height":338,"url":"https:\/\/localhost:8080\/wp-content\/uploads\/2020\/05\/waterfall_plot-min.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/localhost:8080\/waterfall-plot-in-python\/","url":"https:\/\/localhost:8080\/waterfall-plot-in-python\/","name":"Waterfall Plot in Python - machinelearningplus","isPartOf":{"@id":"https:\/\/machinelearningplus.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/localhost:8080\/waterfall-plot-in-python\/#primaryimage"},"image":{"@id":"https:\/\/localhost:8080\/waterfall-plot-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/waterfall_plot-min.jpg","datePublished":"2020-05-09T09:24:27+00:00","dateModified":"2021-05-27T09:12:35+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/localhost:8080\/waterfall-plot-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/localhost:8080\/waterfall-plot-in-python\/#primaryimage","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/waterfall_plot-min.jpg","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/05\/waterfall_plot-min.jpg","width":622,"height":338,"caption":"Waterfall Plot in Python"},{"@type":"WebSite","@id":"https:\/\/machinelearningplus.com\/#website","url":"https:\/\/machinelearningplus.com\/","name":"machinelearningplus","description":"Learn Data Science (AI \/ ML) Online","publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/machinelearningplus.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/machinelearningplus.com\/#organization","name":"machinelearningplus","url":"https:\/\/machinelearningplus.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","width":348,"height":36,"caption":"machinelearningplus"},"image":{"@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/pages\/3283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/comments?post=3283"}],"version-history":[{"count":0,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/pages\/3283\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media\/3462"}],"wp:attachment":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media?parent=3283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}