Matlab - highlight a specific interval using patch -
i highlight specific interval in plot. found way using patch object. problem layout gets messy whenever use it.
here's example of plot:
x = 1:0.05:25; plot(x,sin(x)+sin(100*x)/3); xlabel('x axis'); ylabel('y axis'); title('\omega \delta test'); legend('sin \sigma')
and highlight period:
yl = ylim; patch([5 5 10 10],[yl(1) yl(2) yl(2) yl(1)],'k',... 'facecolor',[.4 .6 .4],'edgecolor',[.4 .6 .4],... 'facealpha',0.3,'edgealpha',0.3)
my results , without patch command:
normal:
messy:
look @ fonts , legend block. ideas on how fix that?
is there better way highlight interval? need choose color , set transparency.
just 1 more question: why have use third input (color) if it's not applied?
thanks in advance!
edit: answer valid matlab versions before 2014b, incredibly useful erasemode
property has been removed hg2 graphic objects on later matlab versions.
i ran problem countless times , had learn live it. times can accept glitches of opengl
renderer if buys me nice transparency effects, in cases not acceptable.
i use patch
objects highlight intervals in many applications, on several curves. there trick can use when transparency not option, erasemode
property of patch object. if set erasemode
property 'xor'
patch not transparent, yet under patch xor
patch pixel colours can still see curves under patch.
this not being transparency rendering, can use default painter
renderer , avoid occasional glitches of opengl
.
so example data:
hp = patch([5 5 10 10],[yl(1) yl(2) yl(2) yl(1)],'k',... 'facecolor','g','edgecolor','g',... 'erasemode','xor') ;
and nice advantage of trick works monochrome display/prints. if cannot use multiple colours, can use 1 colour (if plan black & white printing publication example)
hpx = patch([5 5 10 10],[yl(1) yl(2) yl(2) yl(1)],'b',... 'facecolor','b','edgecolor','b',... 'erasemode','xor') ;
Comments
Post a Comment