Closed rvenegas2018 closed 4 years ago
Hi Roberto,
This is a bit too much of a niche case for me to add it to the boundedline function itself, but you should be able to achieve what you want with a few tweaks to the line and patch returned by boundedline. Here's a quick example:
% An example similar to yours...
T = load('global_sst'); % some example data (from Climate Data Toolbox)
ax(1) = axes('position', [0.1 0.1 0.6 0.8]);
pcolor(T.lon,T.lat,T.sst);
shading flat;
ax(2) = axes('position', [0.75 0.1 0.2 0.8]);
tmean = nanmean(T.sst,2);
bnd = [tmean-min(T.sst,[],2) max(T.sst,[],2)-tmean];
isn = isnan(tmean);
% Start with simple boundedline
[hl,hp] = boundedline(tmean(~isn), T.lat(~isn), bnd(~isn,:), ...
'orientation', 'horiz', 'nan', 'remove', 'alpha');
% Change the patch color so it's shaded based on xdata of each vertex
set(hp, 'cdata', hp.XData, 'facecolor', 'interp');
% Line objects can't change color... but you can fake it with a patch or
% surface object instead
hl2 = patch([hl.XData NaN], [hl.YData NaN], [hl.XData NaN], ...
'edgecolor', 'interp');
% link y-axis and colormaps
set(ax, 'ylim', [-90 90], 'clim', [271 305]);
% remove the original line
set(hl, 'visible', 'off');
The end result:
Mahalo Kelly, very much appreciated!
A follow-up question as with my data the shade looks very light, would it be possible to modify somehow the intensity of shade (alpha)? I tried changing alpha for transparency and playing around but it didn't work...
Note: I just found the way to do this in your code, just by adding 'FaceAlpha' and a value, like this:
set(hp, 'cdata', hp.XData, 'FaceAlpha', 0.75, 'facecolor', 'interp');
Code is good and running, Mahalo, Kelly!
Aloha Kelly,
Thank you so much for developing and making available your function "boundedline.m".
I am wondering if it would be possible to have the line and shade associated with the colorbar (or to add the option, if not available)? I tried the following based on my attached figure: boundedline(x, y, b, 'cmap', cmapYO); where cmapYO is my colormap for my current figure (subplot left) below.
Here is an example I found of a plot/line with colors associated with the colorbar magnitude: https://user-images.githubusercontent.com/48822884/81855738-717de680-94fb-11ea-9790-9d1ef78fbc87.png
This is the figure I am creating and would like to have your suggestions on it is possible to modify the figure (subplot right) to have line and shade associated to colorbar following the idea from the above figure.
Mahalo for your help, very much appreciated! Roberto