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):
image
(source: austringer.net)

Have a look at mplot3d:

# copied from 
# http://matplotlib.sourceforge.net/mpl_examples/mplot3d/wire3d_demo.py

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)

plt.show()

http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#wireframe-plots

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


If you want more, you may also have a look at MayaVi: http://mayavi.sourceforge.net/

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))
waterfall(test)

Leave a Reply

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