MATLAB: Polarhistogram changing rlim creates blue circle

MATLABpolarhistogramrlim

Hello,
When using the polarhistogram function, I've been setting the rlimits by calling rlim([min max]) after calling polarhistogram. This is the only way I know how to set these rlimits. However, it leads to some frustrating behavior. What before was a white background, now has a circle of blue, either filling the whole circle or just part of it (see below)
It's almost as if a circular polar histogram has been plotted on top of my actual data. Any insight into why this happens, or how I can avoid it?
Here's a reproducible example:
This code:
x = [14 13 17 18 19 20 21 14 16 21 10 11 13 14 20 17 13 15];
edges = -190:20:170;
polarhistogram('BinEdges',deg2rad(edges),'BinCounts',x, 'Normalization','probability');
rlim([.03 .09])
Generates this plot:

Best Answer

rlim() is behaving as expected.
The reason you're seeing the additional blue historgrams is because unlike ylim in Cartesian axes, rlim is pushing the objects to the otherside of the polar axes.
Here's an illustration showing the same coordinate at different r-limits. I know this seems bizarre since setting the ylim of Cartesian coordinates cuts off data less than the lower y-limit. But polaraxes behave differently.
clf()
tiledlayout(1,3)
nexttile
polarplot(0, 0.3, 'o','LineWidth', 2, 'MarkerSize', 10)
rlim([0,1])
title('rlim [0,1]')
nexttile
polarplot(0, 0.3, 'o','LineWidth', 2, 'MarkerSize', 10)
rlim([0.3,1])
title('rlim [0.3,1]')
nexttile
polarplot(0, 0.3, 'o','LineWidth', 2, 'MarkerSize', 10)
rlim([0.6,1])
title('rlim [0.6,1]')
Workarounds
> Is there any workaround to this behavior? I think I could subtract the minimum value from my distribution
I've been playing around with it, trying to find a workaround using polarhistogram but haven't come up with anything great yet. I have this nagging feeling that there's a polar axis property that can be set to fix this but I haven't come across it and it may only be in my imagination.
You can't just shift the data because the histogram will still start at 0 no matter what and those sections will be forced to the other side of the axes. You also need to change the RTickLabels (see 3rd example below).
Use Markers
You could always represent the data with markers but that doesn't have the same visual interpretation as a histogram.
x = [14 13 17 18 19 20 21 14 16 21 10 11 13 14 20 17 13 15];
xnorm = x./sum(x);
edges = -190:20:170;
binCenters = edges(2:end)-10;
figure()
polarplot(deg2rad(binCenters([1:end,1])), xnorm([1:end,1]), 'o-')
rlim([.03 .09])
Use lines
Similar to above but with radi lengths instead of interconnected points.
x = [14 13 17 18 19 20 21 14 16 21 10 11 13 14 20 17 13 15];
xnorm = x./sum(x);
edges = -190:20:170;
binCenters = edges(2:end)-10;
theta = deg2rad(binCenters).*[1;1];
rad = [0.03*ones(size(xnorm)); xnorm];
figure()
polarplot(theta, rad, 'bo-')
rlim([.03 .09])
Scale data and RTickLabels
To do this with a histogram, you'd need to scale the data and the rlim tick labels
x = [14 13 17 18 19 20 21 14 16 21 10 11 13 14 20 17 13 15];
desiredRLim = [0.03, 0.09];
xnorm = x./sum(x) - desiredRLim(1);
edges = -190:20:170;
binCenters = edges(2:end)-10;
polarhistogram('BinEdges',deg2rad(edges),'BinCounts',xnorm)
rlim(desiredRLim - desiredRLim(1))
ax = gca();
ax.RTickLabel = compose('%.2f',ax.RTick + desiredRLim(1));