Associating a colorbar to a plot after hand (after using cbfreeze)?
Mostrar comentarios más antiguos
Hi,
I want to change the colormap of a single panel in a multi panel figure using freezeColors and cbfreeze. The code looks like this:
%%Plot
n_plots = 3;
x = -10:10; y = -10:10; [X,Y] = meshgrid(x,y);
for k = 1:n_plots;
h(k) = subplot(3,1,k);
pcolor(h(k),X,Y,X+k);
ch(k) = colorbar('peer',h(k));
ylabel(ch(k),['x+' num2str(k)]);
c_lims(k,:) = get(h(k),'clim');
end
c_lim = [min(min(c_lims)) max(max(c_lims))];
for k = 1:n_plots; set(h(k),'clim',c_lim); end
%%Change colormap of first panel
apply_cmap_to = h(1);
all_plot = findall(gcf,'type','axes','tag','');
all_cbar = findobj(gcf,'tag','Colorbar');
active_plot = apply_cmap_to;
active_cbar = findobj(gcf, 'Type', 'axes', 'Tag', 'Colorbar','Axes', active_plot)
nonactive_plot = all_plot; nonactive_plot(find(nonactive_plot==active_plot)) = [];
nonactive_cbar = all_cbar; nonactive_cbar(find(nonactive_cbar==active_cbar)) = [];
for ii = 1:numel(nonactive_plot); freezeColors(nonactive_plot(ii)); end
for pp = 1:numel(nonactive_cbar), % workaround cbfreeze bug that cbfreeze removes cblabel
hcb = nonactive_cbar(pp);
hy=get(hcb,'ylabel');
ylabel_string=get(hy,'string');
ylabel_fontsize=get(hy,'fontsize');
cbar_position = get(hcb,'position');
new_hcb = cbfreeze(hcb);
new_hy=get(new_hcb,'ylabel');
set(new_hy,'string',ylabel_string,'fontsize',ylabel_fontsize);
set(new_hcb,'position',cbar_position);
end
colormap(active_plot,'hot');
%%Change colormap of second panel
apply_cmap_to = h(2);
all_plot = findall(gcf,'type','axes','tag','');
all_cbar = findobj(gcf,'tag','Colorbar');
active_plot = apply_cmap_to;
active_cbar = findobj(gcf, 'Type', 'axes', 'Tag', 'Colorbar','Axes', active_plot)
nonactive_plot = all_plot; nonactive_plot(find(nonactive_plot==active_plot)) = [];
nonactive_cbar = all_cbar; nonactive_cbar(find(nonactive_cbar==active_cbar)) = [];
for ii = 1:numel(nonactive_plot); freezeColors(nonactive_plot(ii)); end
for pp = 1:numel(nonactive_cbar), % workaround cbfreeze bug that cbfreeze removes cblabel
hcb = nonactive_cbar(pp);
hy=get(hcb,'ylabel');
ylabel_string=get(hy,'string');
ylabel_fontsize=get(hy,'fontsize');
cbar_position = get(hcb,'position');
new_hcb = cbfreeze(hcb);
new_hy=get(new_hcb,'ylabel');
set(new_hy,'string',ylabel_string,'fontsize',ylabel_fontsize);
set(new_hcb,'position',cbar_position);
end
colormap(active_plot,'hot');
For the first panel it works since the colorbars are associated with a certain plot. cbfreeze changes this, so when I try to apply the same code to the second panel, it can not find the colorbar associated with that panel. Is there any way to reset this relation the first time the changes occur (after using cbfreeze) so that
active_cbar = findobj(gcf, 'Type', 'axes', 'Tag', 'Colorbar','Axes', active_plot)
works? Or is there any other way to fix this, find the colorbar that goes with a certain plot for example? I would like to do it without changing cbfreeze.
Much thanks!
Respuestas (0)
Categorías
Más información sobre Colorbar en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!