xline - draw a partial line
이전 댓글 표시
Is there an easy way to get an xline plot for an array of X values, but with the line only taking up the first or last 10% of the Y axis? It's for this plot, where plotting the whole line is obscuring the blue data too much..

This is for a script where the Y axis is logarithmic and its values are not always the same. I could plot the lines in a loop, having calculated the appropriate Y values. But is there a simpler way?
댓글 수: 3
dormant
2024년 1월 10일
이동: Walter Roberson
2024년 1월 10일
@dormant: How about putting the black vertical lines beneath the blue line, so that the blue line is not obscured? That can be done: (1) by plotting the black lines before the blue line, or (2) by reordering the lines in the axes Children property after they are plotted, e.g. using uistack or setting the Children property directly.
Example:
% plot a thick line and a thin line on top:
figure()
h_thick = plot(1:10,'LineWidth',10);
hold on
h_thin = plot(1:10,'LineWidth',2);
% thin line is 1st in axes Children (most recently created):
ax = gca();
ch = get(ax,'Children');
ch == h_thin
% new figure and axes (only necessary for demonstration in Answers):
ax = copyobj(ax,figure());
% get the new handle of the thin line (also only necessary for
% demonstration in Answers):
ch = get(ax,'Children');
h_thin = ch(1);
% reverse the order of the axes Children:
set(ax,'Children',flip(get(ax,'Children')));
% now the thin line is underneath the thick one,
% and the thin line is last in Children:
ch = get(ax,'Children');
ch == h_thin
dormant
2024년 1월 11일
채택된 답변
추가 답변 (3개)
hello
I am not aware that a special version of xline exist , but you can do your own special xline like that (a very crude and simple code that you can save as a function for future massive use) :
simply try with different a and b values to adjust the amount of blank around the data curve
% dummy data
n = 1000;
t = (0:n-1)/n;
y = 0.1 + sin(pi*t/max(t)).^3.*abs(sin(2*pi*10*(t+1*t.^3))); % signal
[PKS,LOCS] = findpeaks(y,t,'SortStr','descend','NPeaks',15);
figure(1)
ylimits = [1e-2 1e1];
semilogy(t,y,'b',LOCS,PKS,'.r','linewidth',2,'markersize',25);grid on
% add my special vertical lines
a = 0.25; % factor on the lower portion (must be < 1)
b = 1.25; % factor on the upper portion (must be > 1)
hold on
for k = 1:numel(PKS)
plot(LOCS(k)*ones(2,1), [ylimits(1) a*interp1(t,y,LOCS(k))],'--k','linewidth',0.5);
plot(LOCS(k)*ones(2,1), [b*interp1(t,y,LOCS(k)) ylimits(2)],'--k','linewidth',0.5);
end
ylim(ylimits);
hold off
Image Analyst
2024년 1월 10일
0 개 추천
dormant
2024년 1월 11일
댓글 수: 1
Image Analyst
2024년 1월 12일
Looks confusing to me unless it's explained somewhere. The red lines don't go to the curve but all go to some constant y value. And the x location of them seems random.
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






