How can I show radial ticks and axis on top of a polar plot?
25 ビュー (過去 30 日間)
古いコメントを表示
Although not a MWE, this is what the code looks like:
figure;
polaraxes; hold on;
polarscatter(vara,varb,[],varc,'.');
c = colorbar;
colormap(map);
In this case, the plot completely hides the ticks and most of the axes in the radial direction.
Is there any way to bring these two elements to the front of the plot?
I tried what's suggested in this answer by a MATLAB Staff, but the function findobj returns an empty array for both line and text.
0 件のコメント
採用された回答
Berk Gezer
2022 年 6 月 2 日
I believe this is what you or anyone else is looking for:
ax = gca;
ax.Layer = 'top';
0 件のコメント
その他の回答 (1 件)
Adam Danz
2020 年 7 月 14 日
編集済み: Adam Danz
2023 年 3 月 3 日
The older answer you pointed to refers to the older polar() function which uses a cartesian plot to create the polar axes and line objects to create the grid. The new and improved polaraxes(), polarplot() and friends are completely different objects with different properties.
Alternative approaches:
Method 1: Plot the grid and rho tick labels manually.
See inline comments for details.
Demo:
% Create main axes
fig = figure();
h = polaraxes(fig);
% Plot the data
polarscatter(h, rand(1,4000)*2*pi, rand(1,4000)*10,'.')
% [Do axis modifications here if needed]
% Recreate grid
th = (0:359)*pi/180;
hold(h,'on')
polarplot(h,th,repmat(h.RTick(:),1,numel(th)), 'k-') % Rho grid
polarplot(h, h.ThetaTick.*[1;1]*pi/180, h.RTick([1,end])', 'k-') %Theta grid
% Remove old grid
h.RGrid = 'off';
h.ThetaGrid = 'off';
% Recreate rho ticks
rTickTheta = 80*pi/180 * ones(size(h.RTick));
th = text(rTickTheta, h.RTick, h.RTickLabel, 'Color','r', ...
'HorizontalAlignment','center','VerticalAlignment','Middle');
% Place transparent white background behind rho tick labels for increased visibility
set(th, 'BackgroundColor', [1 1 1 .5]) % the 4th value controls transparency level
% Remove original rho tick labels
h.RTickLabel = {};
Method 2: Copy the polar axes and lay it on top of the original
This method is a bit more clumsy than method 1 but it also does the job. It copies the empty polaraxes and plots it on top of the orginal polar axes. It then alters the copied grid and labels to increase visibility. The outcome is the same as the image above except this method does not include the BackgroundColor option that method 1 provides. I recommend using method 1.
See inline comments for more details.
Demo:
% Create main axes
fig = figure();
h = polaraxes(fig);
% Before plotting, make copy of axes
h2 = copyobj(h,fig);
h2.Color = 'none'; % see through the top axes
% Plot to the *original* axes which is under the copied axes.
polarscatter(h, rand(1,4000)*2*pi, rand(1,4000)*10,'.')
% Make the grid & tick labels on the copied axies more visible
h2.RColor = 'r';
h2.GridColor = 'k';
h2.GridAlpha = .75;
% Make sure the axis limits and other properties match between the two axes
linkprop([h,h2],'RLim','ThetaLim','Position',...
'ThetaAxisUnits','ThetaDir','ThetaZeroLocation', ...
'ThetaTick','RTick') % Add whatever else you need
2 件のコメント
Adam Danz
2020 年 7 月 15 日
Sounds good! Just a heads up; the transparency of the background is controlled by an undocumented method (the 4rd element of an RGB triplet). In the past, the transparency was lost when saving the figures and re-opening them. I'm not sure if that's been fixed. But if you're using a fully opaque backround (=1) then this won't be a problem at all.
参考
カテゴリ
Help Center および File Exchange で Polar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!