File Exchange

image thumbnail

Alluvial flow diagram

version (2.45 KB) by Alexander Carmeli
Plot flows from sources to sinks and relationships between categories.


Updated 12 Apr 2018

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Four video gamers play computer games during the morning, afternoon, and evening.
A matrix shows how many hours each gamer played during each part of the day.
Use an alluvial flow chart to graphically study the parts of the day when gamers like to play, and how the gamers distribute their play time.
The function was tested using R2008a. A comment showcases how automatic scalar and vector expansions (introduced in R2016b) can greatly simplify expressions.

Cite As

Alexander Carmeli (2021). Alluvial flow diagram (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

Darvid Huhn

Thanks Alexander for your work and sharing.
I could suggest this little add-on, after line 132:
It plots out the information about:
- on the left side: the quantity that each person spends time in total each day.
- on the right side: the quantity that personS spent on parts of the day.

Line 132: [....] end % for each row

n=size(data,1); % return number of rows in data
for i=1:n
left_labels(i) = strcat(left_labels{1,i},':',{' '},num2str(sum(data(i,:))),' h'); % Sum up all data that flows out of a left label and add it to the sring together with a unit

n=size(data,2); % return number of columns in data
for i=1:n
right_labels(i) = strcat(right_labels{1,i},':',{' '},num2str(sum(data(:,i))),' h') % Sum up all data that flows into a right label and add it to the sring together with a unit

% Place left labels

Eleni Livanou

Zhaozheng Hou

Thanks a lot for your great work. The comments and example scripts are clear and helpful! The only thing is I think it would be better if the user can add overall labels for the groups on the left/right.

Bratislav Lukic

Thanks for this great script. I have one little issue, when running test data there seems to be streamlines also for zero value. Anyone had experienced something like that?

Stefan Dukic

Edilberto Amorim

Thanks for sharing this code. How can we specify patch colors?

Roger Oria Fernandez

Hi there,

Thanks for your code. It works perfectly! However, I was to add one more block. Let's say that now, we want to divide morning, afternoon and night in slots of 3 hours ... I've gone through the code and I don't have a clear idea how to do that. In reality, my purpose is to create something more complex...but I think this can solve it (in my case, if you add one more block, call it right_right_labels, I have to link new blocks that were not present in the left labels to from the right to the right to the right_right panel).

Thank you in advance!



Tristany Armangue

Is there a way to set a minimum thickness for the lines? I have data with too large a difference, and some of the lines are pretty much invisible. Thank you!


Is there a way of exporting the resulting plot into a vector file?

Lauren Viarengo

I have been looking for a code to do just this! Well written, clear and easy to use! Thank you!

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!