Colorize bar or line according to magnitude.
5 views (last 30 days)
Show older comments
I have series of data recorded in one column. These are the potential values alone corroded rebar.
I need to find a way to interpret the magnitudes along with the rebar. (Not line graphs, something similar to contour plots with color scale, but one single column of data.). I use MatLab for data analysis, but I could not find a way for this question. A bar or line should be colorize according to magnitude and the distance recorded.
please could you help me to find a way for the graphical interpretation.

0 Comments
Answers (1)
Mathieu NOE
on 18 Mar 2021
hello
it's unclear how you want to associate color with 2 parameters (magnitude and the distance)
fyi , this is one option :
% Examples:
x = linspace(0,4*pi,50);
y = sin(x);
c = abs(y);
map = colormap(jet);
h = ccplot(x,y,c,map);
set(h,'Marker','o');
cbv=colorbar('v');
function h = ccplot(x,y,c,map)
% CCPLOT Conditionally colored plot
%
% h = CCPLOT(X,Y,CONDITION,MAP) plots the vector Y versus vector X
% using conditional coloring. CCPLOT maps each value in vector C to a
% certain color of the specified colormap MAP. CCPLOT returns handles
% to the line objects that can be used to change properties via
% set(...)
%
% Examples:
% x = linspace(0,4*pi,50);
% y = sin(x);
% c = y.^2;
% map = colormap(jet);
% h = ccplot(x,y,c,map);
% set(h,'Marker','o');
% Copyright 2012 Michael Heidingsfeld
% $Revision: 1.0 $ $Date: 2012/08/02 15:33:21 $
if ~(all(size(x) == size(y)) && all(size(x) == size(c)))
error('Vectors X,Y and C must be the same size');
end
N = size(map,1);
cmax = max(c);
cmin = min(c);
cint = (cmax-cmin)/N;
indices = 1:length(c);
status = ishold; % save hold status
for k = 1:N
ii = logical(c >= cmin+k*cint) + logical(c <= cmin+(k-1)*cint);
jj = ones(size(ii)); jj(1:end-1) = ii(2:end);
ii = logical(ii .* jj);
X = x; X(indices(ii)) = NaN;
Y = y; Y(indices(ii)) = NaN;
h(k) = plot(X,Y,'Color',map(k,:));
hold on;
end
if status == 0, hold off; end % reset hold status
end
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!