Simple query: how can I remove radial axes (eliminate the "spokes") on a Compass Plot

3 views (last 30 days)
I've searched but can't find answer to how to remove the "spokes" (light gray radial axes) in a compass plot, such as:
Of course, I can do this in the Figure itself by going to Edit>Figure Properties>Axes etc. But it's not possible to "generate code" from within the figure (File>Generate code). When I try that, I get the mssg:
function createfigure
%CREATEFIGURE
% Auto-generated by MATLAB on 21-Mar-2023 18:36:48
% Create figure
figure;
% polar currently does not support code generation, enter 'doc polar' for correct input syntax
% polar(...);
...and doc polar (or doc compass, for that matter) doesn't seem to say anything about removing axes.

Accepted Answer

Chris
Chris on 22 Mar 2023
Edited: Chris on 22 Mar 2023
I think the developers of these functions don't intend for us to be messing with the grids, or haven't gotten around to making it easy for us.
However, it can be done.
ax = gca; % Get current axes
kids = allchild(ax); % Get the lines and text and whatever else
kids will have all the stuff you'll be interested in (try entering it in the command window without the semicolon). We're looking for things that have their handle visibility set to 'off',
which is everything but the plots.
invis = strcmp(get(kids,'handleVisibility'),'off');
Now, to hide absolutely everything, you could do...
set(kids(invis),'Visible','off');
To instead only hide some things (like spokes), first find those things.
There's definitely a more elegant way to do this, but this is all I've got right now.
lineidx = find(invis & strcmp(get(kids,'Type'),'line'));
spokes = false(size(kids));
for idx = 1:numel(lineidx)
kd = kids(lineidx(idx));
if numel(kd.XData) == 2
spokes(lineidx(idx)) = true;
end
end
set(kids(spokes),'Visible','off');
It looks as if, in many cases, the spokes will be found at kids(end-14:end-9), in which case you could disregard the preceding block and simply:
set(kids(end-14:end-9), 'Visible','off');
Does that help?
  3 Comments
Stephen
Stephen on 22 Mar 2023
Whoops, incomplete script. Hit <send> too soon. Should be:
ax = gca; % Get current axes
kids = allchild(ax); % Get the lines and text and whatever else
set(kids(spokes),'Visible','off'); % delete the "spokes" (radial lines)
Chris
Chris on 23 Mar 2023
Glad it worked for you!
To be clear, though, "spokes" is just a variable that we defined. If you start from a clean workspace you'll have to locate them again.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!