2012-06-26 92 views
13

是否有一個python模塊可以像MATLAB那樣做瀑布圖?我搜索了'numpy瀑布','scipy瀑布'和'matplotlib瀑布',但沒有找到任何東西。瀑布圖python?

回答

5

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

我不知道如何得到的結果作爲Matlab的確實不錯。


如果您想了解更多,您也可以看看MayaVihttp://mayavi.sourceforge.net/

4

維基百科類型的Waterfall chart一個也可以得到這樣的:

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) 
+0

克里斯莫菲特由不錯的帖子有一些更多的解釋(他明顯受到以上代碼的啓發:-)):請參閱http://pbpython.com/waterfall-chart.html – kadee