How to include a vertical scale besides of a polar plot ?

I want to draw a vertical bar besides of a polar plot like in the picture attached. Also the legend in the same position as shown in figure.
Edit: This issue got solved but the i want to allocate ticks and ticklabels by using somecode as shown below. It is not working properly.
a=0:0.1:2*pi;
b=rand(size(a));
c=0.5*rand(size(a));
figure
hold off
polar(a,b,'g-')
hold on
polar(a,c,'r-')
tick = ceil(min(b))-1:0.5:ceil(max(b));
hBar.Ticks = [tick];
hBar.TickLabels = tick;

 채택된 답변

This is easy, but you need to use handles if you want the figure to look like the one you show. And also, you have to think of the bar, as the polar plot will have the values on the concentric circles of the polar plot. Anyway, here is the code:
First, some data
% the data
a=0:0.1:2*pi;
b=rand(size(a));
c=0.5*rand(size(a));
Now display it in a figure with polar plot
% create the plots
figure
hold off
polar(a,b,'g-')
hold on
polar(a,c,'r-')
Now add the legend, grab the handle and reposition:
hLegend = legend('a','b','Location','NE');
hLegend.Position = [0.7830 0.8806 0.1036 0.0869];
I would say that the figure looks good so far, but if you want the bar, add it and grab the handles, change the position, the ticks and the labels of the ticks:
% Add the bar, grab handles
hBar = colorbar;
hBar.Position = [ 0.1112 0.1024 0.001 0.8167];
hBar.Ticks = [0.05:0.1:1 ];
hBar.TickLabels = [10 0 -10 -20 -30 -30 -20 -10 0 10 ];

댓글 수: 11

I want to create the ticks and tick labels by means of code as illustrated below, but the tick labels are not getting updated accordingly. Is there any way to do like that ?
tick = ceil(min(b))-1:0.5:ceil(max(b));
hBar.Ticks = 0:0.5:length(tick);
hBar.TickLabels = tick;
To do that, you need to make sure that your two vectors have the same lengths:
>> ceil(min(b))-1:0.5:ceil(max(b))
ans =
0 0.5000 1.0000
>> 0:0.5:length(tick)
ans =
Columns 1 through 5
0 0.5000 1.0000 1.5000 2.0000
Columns 6 through 7
2.5000 3.0000
>>
So, the problem is on the values that you are passing. I still think that the bar is not necessary as the values are included directly in the plot, try the following:
%%
log_b = 10*log(0.1*b);
log_c = 10*log(0.1*c);
% create the plots
hold off
polarplot(a,log_b,'g-')
hold on
polarplot(a,log_c,'r-')
rlim([min([log_b log_c]) max([log_b log_c])])
There you have the values of the two plots in logarithmic scale and in the polar grid.
If this solves your question, please accept the answer. If not, let me know.
Yeah this solves the problem, I have only one last question about how to thicken only the outer radial border of the plot and how can we control the number of radial minor grid lines ?
ax = polaraxes;
ax.LineWidth = 1; % This makes every line thicker
ax.RMinorGrid = 'on'; % Puts more number of radial divisions and making plot to bearly visible
That is a bit more tricky ... you could plot another line that lands exactly on the outer radial border and would visually give your result.
For the grid, you can keep the minor ones, but then make the major ones darker, e.g.
ax.GridAlpha=0.5;
and that gives a good view
I am facing one trouble when i used the location property rather than position as you illustrated. Now i am getting this colormap instead of a simple vertical line as obtained when position property is used. How can i turn off this colormap and making only vertical scale visible ?
Notice that the position property handles the width of the bar:
hBar.Position = [ 0.1112 0.1024 0.001 0.8167];
by using 0.001 the bar becomes very thin and thus has no colours.
but i have to make the bar to be of same length as of polar plot in parallel. This position argument is not helping in achieving what i wanted.
Grab the handle of the axes before plotting, then check the position
h1=axes;
>> polar(a,c,'r-')
>> h1.Position
ans =
0.1300 0.1100 0.7750 0.8150
Then when you create your colorbar you can match the positions:
>> hBar = colorbar;
>> hBar.Position
ans =
0.7568 0.1095 0.0381 0.8167
>>
I didn't get your can you explain it in a detailed manner

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Polar Plots에 대해 자세히 알아보기

제품

릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by