Matlab pre-HG2'de colormap
değişikliğini engellemek için belgesiz işlevselliklere başvurmanıza gerek yoktur. 'Colormap'
'un 'PostSet'
olayına bir dinleyici bağlayabilirsiniz. senin figürü yok zaten, sadece tip ise
hızlı bir örnek olarak,: konsolda
lh = addlistener(h.fig , 'Colormap' , 'PostSet' , @(h,e) disp('cmap changed !'))
ve bir mesaj her zaman alacak sen colormap
değiştirin.
- (örneğin
hsv
için jet
gelen) bir diğerine tamamen colormap
değiştirmek
- Eğer renk haritası (bölme sayısı) boyutunu değiştirmek: Olay olup tetiklenir unutmayın. (örn .:
colormap(jet(5))
)
- "Etkileşimli renk eşlem kaydırması" gui aracını kullanırsınız.
Not o olay olacak değil tetik sen caxis
kullanırsanız. Bu komut, colormap
'un kendisini değiştirmez, ancak bazı renklerin haritada nasıl eşleştirildiği. Bu komutu kullanırsanız, pcolor
'unuz değiştirilecektir (renk haritası olmamasına rağmen). caxis
komutu geçerli axes
'un (figure
değil!) CLim
özelliğini değiştirir. Yani bunu tespit etmek istiyorsanız, bu özelliğe doğru eksende bir dinleyici eklemeniz gerekir. Böyle bir şey: Daha uygulamalı örnek olarak
lh = addlistener(gca , 'CLim' , 'PostSet' , @(h,e) disp('clim changed !'))
, burada colormap
değiştirildi her zaman tepki gösterecektir biraz demo. Her değişiklikte contour
çiziminize ne yapmayı planladığınızı bilmediğimden, sadece bir şeyler yaptığını göstermek için birkaç özelliği değiştirdim. Bunu yapman gerekeni yap.
function h = cmap_change_event_demo
%// SAMPLE DATA. create a sample "pcolor" and "contour" plot on a figure
nContour = 10 ;
[X,Y,Z] = peaks(32);
h.fig = figure ;
h.pcol = pcolor(X,Y,Z) ;
hold on;
[~,h.ct] = contour(X,Y,Z,nContour,'k');
h.cb = colorbar
shading interp
colormap(jet(nContour+1)) %// assign a colormap with only 10+1 colors
%// add the listener to the "Colormap" property
h.lh = addlistener(h.fig , 'Colormap' , 'PostSet' , @cmap_changed_callback)
%// save the handle structure
guidata(h.fig , h)
function cmap_changed_callback(~,evt)
%// disp('cmap changed !')
hf = evt.AffectedObject ; %// this is the handle of the figure
cmap = evt.NewValue ; %// this is the new colormap. Same result than : cmap = get(hf,'Colormap') ;
h = guidata(hf) ; %// to retrieve your contour handles (and all the other handles)
nColor = size(cmap,1) ; %// to know how many colors are in there if you want matching contours
%// or just do something useless
set(h.ct , 'LineColor' , rand(1,3)) %// change line color
set(h.ct , 'LineWidth' , randi([1 5],1)) %// change line thickness

son MATLAB sürümü (post HG-2) için bir çözüm var mı? – oro777
@ oro777. Üzgünüm, ancak en son Matlab sürümü için çalışmasını sağlamak için hızlı bir yol bulamadım. – Hoki