### Colored longitudinal river profiles

Did you ever face the problem that you wanted to plot additional variables together with the two spatial dimensions of a river profile. One such variable could be *ksn* values, or gradient, or lithological identifiers. I recently had this problem, then coded a solution, and now uploaded an updated version of STREAMobj/plotdz.

Such additional variables must be available as so-called node-attributed lists (nal). These lists are column vectors that have as many elements as there are nodes in the stream network. A STREAMobj S has a couple of such nal as properties, e.g. S.x, S.y or S.IXgrid. S.x and S.y are coordinate vectors that locate each node in a projected coordinate system. S.IXgrid is a vector of linear indices into the DEM from which S was derived. nal are returned by a number of STREAMobj methods such as STREAMobj/gradient, STREAMobj/streamorder, STREAMobj/curvature, and STREAMobj/chitransform, among others. Alternatively, you can derive a nal using getnal. For example, a nal with elevation values is simply obtained by

z = getnal(S,DEM);

Now how can you plot colored river profiles. Line objects as produced by the function plot do not support gradually varying colors. As far as I know, there are three work-arounds. The first approach is to plot each line segment with variable colors using the low-level function line. This, however, would probably take ages for large stream networks with thousands of individual line segments. The second approach is to plot the line as a surface with colored edges. This old-time-hack works quite well and leaves you with all the options that surface objects offer. The third approach is one that I came across when reading through Yair Altman’s undocumented MATLAB blog. He reports on some undocumented line properties that were introduced with MATLAB’s new graphics engine in R2014b. I implemented the surface approach and the undocumented approach and let you choose.

Ok, now let’s see the updated plotdz-function in action:

load exampleDEM DEM = GRIDobj(X,Y,dem); FD = FLOWobj(DEM,'preprocess','carve'); A = flowacc(FD); S = STREAMobj(FD,A>100); S = klargestconncomps(S); z = imposemin(S,DEM); s = streamorder(S); subplot(2,1,1) plotdz(S,DEM,'color',s,'LineWidth',1,'cbarlabel','Stream order') g = gradient(S,z); c = chitransform(S,A,'mn',0.45); subplot(2,1,2) plotdz(S,DEM,'color',g,'LineWidth',1,'distance',c,'cbarlabel','Gradient [m/m]') xlabel('\chi [m]')

Now that looks quite ok. Also note the option to modify the values of the upstream distance that allows you to easily plot Χ-plots without using the function chiplot.

Hope that functions turns out to be useful for you.

October 26, 2016 at 4:12 am

Wolfgang, this was overdue. Great job!

May 8, 2017 at 3:47 pm

Dear Wolfgang, many thanks for your impressive work!

When trying to reproduce this example on the srtm_bigtujunga30m_utm11.tif DEM, I got this error on the plotdz command: “Error using plotdz

‘LineWidth’ is not a recognized parameter. For a list of valid name-value pair

arguments, see the documentation for plotdz.”

When I am trying to run: plotdz(S,DEM,’color’,s)

I get the following error: “Error using plot

Color value must be a 3 element vector

Error in STREAMobj/plotdz (line 172)

ht = plot(d,z,’-‘,’Color’,p.Results.color);”

How can I proceed? many thanks!

May 8, 2017 at 6:41 pm

Hi Alberto, thanks for your comment. Are you using the latest version of topotoolbox? Only the latest version available here: https://github.com/wschwanghart/topotoolbox supports the option as well as colored profile plots. It doesn’t work if you have downloaded the version here: https://github.com/csdms-contrib/topotoolbox .

Hope this helps,

W.

May 10, 2017 at 3:57 pm

It helped a lot!

Thanks,

Alberto