copying colorbar from one figure to another and replacing first YTick

9 ビュー (過去 30 日間)
Marc Jakobi
Marc Jakobi 2014 年 7 月 11 日
回答済み: Marc Jakobi 2014 年 7 月 15 日
Hi. I have a 60x60 matrix "count" (containing values between 0 and >1000) that I would like to make an imagesc from, using a logarithmic scale, by first creating a non logarithmic one with a logarithmic colorbar and then creating a logarithmic one and copying the logarithmic colorbar from the first one (so the colors in the image and the colorbar match the values).
Here is my attempt so far
figure(1) %first figure
count2=count+1; %add 1, because log10(0) not defined
imagesc(count2') %image with real values
cbr = colorbar('Yscale', 'log'); %logarithmic colorbar
figure(2) %second figure
imagesc(log10(count2')) %logarithmic image
set(gca,'YDir','normal')
a = get(1,'children'); %extract colorbar from first figure
copyobj(a(1),2); %copy to second figure
close Figure 1
The problem is that the colours from the image and the colorbar match, but the colorbar covers part of the figure. I would like the second figure to resize when copying the colorbar. Also, since I had to add 1 to count for the logarithmic scaling, I would like to replace the YTick 10^0 at the bottom of the colorbar with 0. For the others YTicks it doesn't matter if the accuracy is +- 1.
Thanks for any help!

採用された回答

Marc Jakobi
Marc Jakobi 2014 年 7 月 15 日
Okay, I found a workaround using xlim, removing the border and making the background white. There's still a little bit of the x-axis behind the colorbar, but it looks decent:
figure(1) %first figure
count2(count2 == 0) = 1; %log(0) not defined - replace all zeros in count
imagesc(count2') %real values, but "wrong" colormap
cbr = colorbar('Yscale', 'log'); %logarithmic colorbar
figure('Color',[1 1 1]) %second figure with white background
imagesc(log10(count2')) %logarithmic image with colormap that fits colorbar 1
set(gca,'YDir','normal') %flip image
a = get(1,'children'); %extract colorbar from figure 1
copyobj(a(1),2); %copy to figure 2
close Figure 1
xlim([1 67]) %shrink imgage, so that colorbar doesn't overlap
box off %rempove frame (that still overlaps colorbar)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by