matlab – Waterfall plot python?

matlab – Waterfall plot python?

You can do a waterfall in matplotlib using the PolyCollection class. See this specific example to have more details on how to do a waterfall using this class.

Also, you might find this blog post useful, since the author shows that you might obtain some visual bug in some specific situation (depending on the view angle chosen).

Below is an example of a waterfall made with matplotlib (image from the blog post):

Have a look at mplot3d:

# copied from 

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection=3d)
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

I dont know how to get results as nice as Matlab does.

If you want more, you may also have a look at MayaVi:

matlab – Waterfall plot python?

The Wikipedia type of Waterfall chart one can obtain also like this:

import numpy as np
import pandas as pd

def waterfall(series):
    df = pd.DataFrame({pos:np.maximum(series,0),neg:np.minimum(series,0)})
    blank = series.cumsum().shift(1).fillna(0)
    df.plot(kind=bar, stacked=True, bottom=blank, color=[r,b])
    step = blank.reset_index(drop=True).repeat(3).shift(-1)
    step[1::3] = np.nan
    plt.plot(step.index, step.values,k)

test = pd.Series(-1 + 2 * np.random.rand(10), index=list(abcdefghij))

Leave a Reply

Your email address will not be published. Required fields are marked *