MATLAB Answers

How to enable the colorbar to only show the vertical scale with values ?

1 ビュー (過去 30 日間)
Mahesh Babu Dhanekula
Mahesh Babu Dhanekula 2020 年 8 月 13 日
編集済み: Adam Danz 2020 年 8 月 14 日
I am using a colorbar command to have a vertical scale besides my polarplot. When its position property is used it is working fine, but i want it to appear as the same size of the polarplot. I have used the location propert to make it appear so. But now the problem is it was showing colormap with colors. I have attached the pictures and link to my previous answered question. All this mess occurs because i want my legend to be displayed under the plot so i have used outside position argument of legend.

  4 件のコメント

表示 1 件の古いコメント
Adam Danz
Adam Danz 2020 年 8 月 13 日
Are you using polar() or polarplot()? The link to your previous questions shows both, so which one are you using? The correct answer should be polarplot unless you're using a release of matlab prior to r2016a.
Also, it would be easier to help if you provide a working example that we can copy and run. The inputs could be attached as a mat file or they could be fake data created within the code that you share.
Mahesh Babu Dhanekula
Mahesh Babu Dhanekula 2020 年 8 月 13 日
I am using polarplot() only and in first link you can see my code and answers to the code to attach a scale. That is all i am using. In addition i have modified the code with exceptions as below.
a=0:0.1:2*pi;
b=rand(size(a));
c=0.5*rand(size(a));
% create the plots
figure
hold off
polarplot(a,b,'g-')
hold on
polarplot(a,c,'r-')
hLegend = legend('a','b','Location','SouthOutside');
% hLegend.Position = [0.7830 0.8806 0.1036 0.0869];
% Add the bar, grab handles
hBar = colorbar;
% hBar.Position = [ 0.1112 0.1024 0.001 0.8167];
hBar.Location = 'WestOutSide'
hBar.Ticks = [0.05:0.1:1 ];
hBar.TickLabels = [10 0 -10 -20 -30 -30 -20 -10 0 10 ];
Mahesh Babu Dhanekula
Mahesh Babu Dhanekula 2020 年 8 月 13 日
Dear jonas, i don't know about how to create separate axis. Please see the code in comments.

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

採用された回答

Adam Danz
Adam Danz 2020 年 8 月 13 日
編集済み: Adam Danz 2020 年 8 月 14 日
The plot below was produced using your exact code as it appears in the comment under the question plus the following two lines at the end,
hBar.Position(3) = 0.00001; % Make it narrow
hBar.Position(1) = 0.15; % move it leftward
Is this what you're looking for?
Using r2020a Update 5.

  1 件のコメント

Adam Danz
Adam Danz 2020 年 8 月 13 日
BTW, I have no idea how to interpret that scale.
Why are there two 0s and 10s?
Why does it go from -10 to 0 at the bottom?
What do those values even mean? -- you could use ylabel(hBar, 'Label')

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

その他の回答 (1 件)

jonas
jonas 2020 年 8 月 13 日
編集済み: jonas 2020 年 8 月 13 日
Not sure if this answers your question, but it's an alternative to using a colorbar for scale. Also did not use the "outside" argument of legend as you mentioned it being problematic.
a=0:0.1:2*pi;
b=rand(size(a));
c=0.5*rand(size(a));
% create the plots
figure
hold off
ax(1) = gca;
polar(a,b,'g-')
hold on
polar(a,c,'r-')
%add legend and change position
hLegend = legend('a','b','orientation','vertical','location','south');
hLegend.Position(1:2) = [0.8 0.8]
%make new axis and align with first one
ax(2) = axes('color','none');
ax(2).XAxis.Visible = 'off';
ax(2).Position([2,4]) = ax(1).Position([2,4]);

  0 件のコメント

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by