Is there a python module that will do a waterfall plot like MATLAB does? I googled 'numpy waterfall', 'scipy waterfall', and 'matplotlib waterfall', but did not find anything.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Extract matrix elements using a vector of column i
- Evil ctypes hack in 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):
(source: austringer.net)
Have a look at mplot3d:
I don't 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/
The Wikipedia type of Waterfall chart one can obtain also like this:
I have generated a function that replicates the matlab waterfall behaviour in matplotlib. That is:
I started from two examples in matplotlib documentation: multicolor lines and multiple lines in 3d plot. From these examples, I only saw possible to draw lines whose color varies following a given colormap according to its z value following the example, which is reshaping the input array to draw the line by segments of 2 points and setting the color of the segment to the z mean value between these 2 points.
Thus, given the input matrixes
n,m
matrixesX
,Y
andZ
, the function loops over the smallest dimension betweenn,m
to plot each of the waterfall plot independent lines as a line collection of the 2 points segments as explained above.Therefore, plots looking like matlab waterfall can be easily generated with the same input matrixes as a matplotlib surface plot:
The function assumes that when generating the meshgrid, the
x
array is the longest, and by default the lines have fixed y, and its the x coordinate what varies. However, if the size of they
array is longer, the matrixes are transposed, generating the lines with fixed x. Thus, generating the meshgrid with the sizes inverted (len(x)=60
andlen(y)=500
) yields:To see what are the possibilities of the
**kwargs
argument, refer to the LineCollection class documantation and to itsset_
methods.