13
votes

Consider the following example code:

load sumsin; 
s = sumsin+10; % example data series
time = linspace(0,5*24,1000);

figure(1);
subplot(311);
plot(time,s,'k');

subplot(312);
plot(time,s,'k');
hold on;
[s_denoised,~, ~] = wden(s,'minimaxi','s','sln',1,'db4');
plot(time,s_denoised,'r');

subplot(313);
plot(time,s,'k');
hold on;
plot(time,s_denoised,'r');
xlim([20 40]);

Resulting in enter image description here

I would like to alter this plot by inserting lines between subplot 2 and 3 to show that subplot 3 is a portion of subplot2. For example:

enter image description here

How can this be achieved in matlab?

Edit:

I was thinking of something along the lines of generating a invisible axes over the entire figure, obtain the position of each subplot, the location of 20 and 40 will be a certain percentage of the subplot width so I could use the annotation command from here to start a line and then apply the same method to the third subplot to connect the lines with the desired location. I have trying this, but no solution so far.

3
mathworks.com/help/matlab/creating_plots/… I think you could rework this example to achieve what you're after.Dan

3 Answers

12
votes

Just for the sake of the answer, you could use annotation objects to get the effect that you're looking for, as correctly suggested in a comment. Note that their coordinates have to be normalized to the [0, 1] range with respect to the figure window, so it might be quite tedious to adjust them.

This does get the job done, but it's horrible. Don't do it this way.

Example

Since I don't have your original data, I'll draw something of my own (but similar to yours):

t = linspace(0, 120, 1000);
s_denoised = sin(t / 2);
s = s_denoised + 0.2 * randn(size(s_denoised));
subplot(3, 1, 1), plot(t, s, 'k')    
subplot(3, 1, 2), plot(t, s, 'k', t, s_denoised, 'r')    
subplot(3, 1, 3), plot(t, s, 'k', t, s_denoised, 'r'), xlim([20 40])

Now let's add "annotation" lines like you want:

annotation('doublearrow', [.26 .39], [.38 .38]); %// Top double-arrow line
annotation('doublearrow', [.13 .9], [.34 .34]);  %// Bottom double-arrow line
annotation('line', [.325 .325], [.38 .37]);      %// Top little connector
annotation('line', [.515 .515], [.35 .34]);      %// Bottom little connector
annotation('line', [.325 .515], [.37 .35]);      %// Line

Result:

result image

6
votes

A bit late in the game, but still it can be beneficial to know of these optional tools that are available at the file exchange (FEX):

inset2DAbsolute - creates an axes inset, defined using the larger axes, and corresponding annotations.

enter image description here

On-figure magnifier - is a zooming tool for 2D graphics of images on the same plot. It is composed of two blocks (the secondary axes and the magnifier). The secondary axes, which can be arbitrarily allocated within the limits of the figure, displays the area marked by the magnifier.

enter image description here

1
votes

Interesting question.

However, from my experience, beautification of graphs and plots can be done more efficiently using graphics software.
I usually use excel + powerpoint for this purpose.

Therefore, my advice (which is not exactly a good answer for your question) is:

  • export your data to excel, using xlswrite

  • use excel to create the desired plots.

  • copy-paste the plots to power point for "hand-crafted" finishing...