How to add fixed Colorbar based on a vector for 2D scatter plot with 3 vectors

11 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2018 年 10 月 23 日
コメント済み: Jon Hinwood 2020 年 10 月 15 日
I want to compare two [2D scatter] plots that both have three variables (x,y,z). I'm plotting x against y and showing vector z for both plots by color. I need to make the colorbar fixed so I can compare the two plots. How can I make this colorbar range fixed for both? Thank you in advance
if true
figure
pointsize = 10;
scatter(x1, y1, pointsize, z1)
colorbar;
figure
pointsize = 10;
scatter(x2, y2, pointsize, z2)
colorbar;
end
  1 件のコメント
Jon Hinwood
Jon Hinwood 2020 年 10 月 15 日
I have tried using caxis, which I use with the plot command, but it has no effect and the range is set automatically to the full range of my data. I have tried placing the caxis command before, after the specification of colormap and before and after the call to scatter and in all 4 positions. Also tried rebooting computer and repeating the trials.
I did find that caxis only worked with plot if the caxis command was after the colormap and before the plot command. I an using Matlab R2019b Academic with Windows 10 both fully updated. Help please!
Jon. 15 Oct 2020

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

採用された回答

Star Strider
Star Strider 2018 年 10 月 23 日
One option is to normalize the ‘z’ values by scaling them with respect to the range of both ‘z1’ and ‘z2’:
figure
pointsize = 10;
scatter(x1, y1, pointsize, (z1-min([z1(:);z2(:)]))/max([z1(:);z2(:)]))
colorbar;
figure
pointsize = 10;
scatter(x2, y2, pointsize, (z2-min([z1(:);z2(:)]))/max([z1(:);z2(:)]))
colorbar;
The colorbar will be the same for both.
  4 件のコメント
Yaser Khojah
Yaser Khojah 2018 年 10 月 23 日
Thanks a lot for your help. It worked finally. I just need to find a better way know to see these colors since I have problem with seeing color haha but thanks a lot.
Star Strider
Star Strider 2018 年 10 月 23 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by