Highlight a part of a plot by drawing it in a different color

爱⌒轻易说出口 提交于 2020-01-11 07:38:07

问题


Given a plot with e.g. a curve like shown on the following figure I want to highlight the curve in the interval 150 <= x <= 200. I would prefer simply drawing this interval in red instead of blue.

Is there a better way to do this than splitting my curve in 3 sets / 3 connecting curve parts? (3 intervals, first one for blue, sencond one for red, third one again for blue). Thanks for any hint!


回答1:


A quick example:

%# plot data
x = linspace(0,2*pi,75);
y = sin(x);
plot(x, y, 'b.')

%# higlight points of interest
idx = (4 <= x & x <= 6);
hold on, plot(x(idx), y(idx), 'r.')
hold off




回答2:


The proper way to do it would be to provide an n*3 matrix of color values, for n data points.

C = zeros(size(x,2), 3);
C(x>=150 & x<=200,1) = 1; % red
C(x<150 | x>200,3) = 1; % blue
scatter(x, y, 25, C, 'd', 'filled');


来源:https://stackoverflow.com/questions/11171384/highlight-a-part-of-a-plot-by-drawing-it-in-a-different-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!