How do you set the scale on a color bar from the figure window?

56 ビュー (過去 30 日間)
JG
JG 2022 年 1 月 19 日
コメント済み: Voss 2022 年 1 月 24 日
I use imagesc to create a plot of x,y,z data. That generats a figure window. I add the color bar to the figure window and then zoom in on the area of interest. I want to change the range of the color bar to give me better detail in the region of interest. How do I do this from the tools given on the figure window? I don't want to have to write a scrpit to generate such a simple plot.
  1 件のコメント
Rik
Rik 2022 年 1 月 20 日
You would have to zoom in on the colorbar as well.
What you describe is actually fairly complex. It can be done in a function, but it may require adapting the colorbar so thoroughly that it would be easier to use a second axes object explicitly.

サインインしてコメントする。

採用された回答

JG
JG 2022 年 1 月 24 日
Soooo
Looking at the responses (thank you), it appears that I what I want to do cannot be done. I wanted to avoid writing a script for such a simple operation. The ability to zoom in the view, and then zoom in scale isn't an unreasonable operation. Scripts are great if you have a process that repeats, but are a burdend if all you want to do is take a quick look at a one off plot.
  2 件のコメント
Rik
Rik 2022 年 1 月 24 日
Zooming in is a simple operation, as is adjusting the color axes (simply call caxis). You want to combine the two, but not just that, you also want the adjustment to take account of the specific region you selected.
Why do you insist that it is simple?
(XKCD 1425, copyright Randall Monroe, CC 2.5 BY-NC)
Voss
Voss 2022 年 1 月 24 日
By the way, @JG, you have avoided writing a script to do it, because we've written it for you; you merely have to copy and paste; what's simpler than that?

サインインしてコメントする。

その他の回答 (1 件)

Voss
Voss 2022 年 1 月 20 日
i don't know how to do it from the figure editor tools, but you can do it with a few lines of code, below. To demonstrate, I'll create a few figures with images and colorbars here, just to show the process (they have to be separate so you can see the various steps - in reality this would all be within your one figure):
figure(); imagesc(); colorbar();
Now zoom in:
figure(); imagesc(); colorbar();
set(gca(),'XLim',[20 40],'YLim',[30 50]);
One more identical figure, zoomed-in, preparing to adjust the colorbar limits:
figure(); imagesc(); colorbar();
set(gca(),'XLim',[20 40],'YLim',[30 50]);
Then these lines do the colorbar limits adjustment:
im = findobj(gca(),'Type','image');
cdata = get(im,'CData');
xl = get(gca(),'XLim');
yl = get(gca(),'YLim');
xl = max(1,min(size(cdata,2),[floor(xl(1)) ceil(xl(2))]));
yl = max(1,min(size(cdata,1),[floor(yl(1)) ceil(yl(2))]));
cdata = cdata(yl(1):yl(2),xl(1):xl(2),:);
set(gca,'CLim',[min(cdata(:)) max(cdata(:))]);
  1 件のコメント
Voss
Voss 2022 年 1 月 24 日
@JG: You can make this code into a function (attached), and set it up so the function is called automatically when you zoom/pan:
figure(); imagesc(); colorbar();
set(zoom,'ActionPostCallback',@adjust_color_limits);
set(pan,'ActionPostCallback',@adjust_color_limits);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by