Clear Filters
Clear Filters

Is it possible to use a subplot grid to obtain as good or better resolution than that provided by the stackedplot function?

4 views (last 30 days)
I am working on a plot that requires a lot of custom markup. I was able to use a subplot grid to get all the custom markup added. See below:
However, during the process, I also tried the stackedplot function which provided superior resolution. If you notice, the dynamics of each time-series trace are much easier to see. This is still the case when I match the LineWidth to the subplot's LineWidth, which was 2. The problem with this function is that it doesn't provide enough customization to get all the markup added. See below:
So, is it possible to modify the subplot in some way to get a resolution like that seen by the stackedplot function, or even greater? I tried cutting off the y-axis limits in the subplot grid, but that results in a loss of data.
Thanks for your time.
  3 Comments
Bryan Conklin
Bryan Conklin on 23 Apr 2020
Edited: Bryan Conklin on 23 Apr 2020
Thanks dpb. I was able to replicate your example on my own graph.
Instead of using the stackedplot each time as a guide, I ended up just manually defining the subplot positions based on how many were plotted and that worked. Things are tight, but resolution is maximized (more than stackedplot) while avoiding any clipping.
If you submit as answer I can accept.
dpb
dpb on 24 Apr 2020
Done. :) I seem to often start off with the idea of just throwing out an idea and then it "just keeps on growing!"

Sign in to comment.

Accepted Answer

dpb
dpb on 24 Apr 2020
I've never tried to build anything with that many traces as separate subplots but I don't see why you couldn't have the same resolution if you set the axes limits the same as the individual axes limits in the stackedplot -- they're essentially the same thing excepting the subplot creates a figure which contains axes with space for labels and all like miniature figures instead of just more bare axes.
y=randi([-50 50],1000,2); % just some random data
figure
hSP=stackedplot(y); % example stacked plot to see how big is...
SPposn=hSP.Position; %
% examination shows [Left Bottom Width ...] same for stacked plot axes both subplot axes
% within the overall position. Height is what is different -- the sum of heights subplots
% < height of same number of lines in stacked plot cuz don't leave room for the axes
% as subplot() does...
figure
for i=1:2, hAx(i)=subplot(2,1,i); end % and two subplots to test the idea
AXposn=reshape([hAx.Position],4,[]).'; % the position vectors for each subplot (top to bottom)
dHt=SPposn(:,4)-sum(AXposn(:,4)); % the differential total height between to figures
AXposn(:,4)=AXposn(:,4)+dHt/2; % split the difference and add to subplot heights
AXposn(1,2)=AXposn(1,2)-dHt/2; % lower the bottom of top to make up for added height
hAx(1).Position=AXposn(1,:); % set each subplot to new position...
hAx(2).Position=AXposn(2,:); % top grows down, bottom grows up
hXAx=get(hAx,'XAxis'); % get the XAxis numeric ruler handles
cellfun(@(hNR) set(hNR,'Visible','off'),hXAx) % turn x axis off
% now ready to plot into adjusted axes...altho could plot first, then adjust position.
axes(hAx(1)) % first suplot
hold on % keep plot from mucking on what we've done
plot(y(:,1)) % same data to compare visual
axes(hAx(2)) % ditto same for lower subplot...
hold on
plot(y(:,2))
Result is that actually have slightly more space in the subplot(() it appears than in stacked plot --there's still a little background between the two plots there and none betwee two subplots. Apparently stackedplot() uses an internal shrinkage factor on actual individual axes it creates within the overall larger container axis. I didn't try that refinement here...but a "roll your own" wouldn't be too hard to put together for specific purpose if don't try to make it handle all the bells and whistles.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!