# Illustrate two close curves

31 views (last 30 days)

Show older comments

Hi all, I have I was wondering what is a good way of plotting two curves that are close to each other. E.g.:

x = linspace (0,100,101); % x-coordinates

a1 = 1;

a2 = 1.001;

y1 = x*a1;

y2 = x*a2;

Plotting them as follows clearly does not help to distinuish between the two curves easily:

plot(x,a1,x,a2)

I don't want to zoom the plot, or plot their difference, as this does not serve my goal. I reckon using logarithmic axes might help, but:

set(gca,'YScale','log');

or

set(gca,'XScale','log');

or both of the above did not help. Any ideas?

##### 3 Comments

### Accepted Answer

Ameer Hamza
on 1 May 2020

At this closeness, there is no good way to plot them on the same graph and distinguish them. One way is to use the different markers on both lines

x = linspace(0,100,101); % x-coordinates

a1 = 1;

a2 = 1.001;

y1 = x*a1;

y2 = x*a2;

plot(x,y1,'.-',x,y2,'+-')

Other way (which I prefer) is to create a small new axes and zoom on a small portion of the line to show the difference

x = linspace(0,100,101); % x-coordinates

a1 = 1;

a2 = 1.001;

y1 = x*a1;

y2 = x*a2;

fig = figure;

ax = axes();

plot(x,y1,x,y2);

x2 = linspace(39.6, 40);

y12 = x2*a1;

y22 = x2*a2;

ax_small = axes('Position', [0.25 0.55 0.25 0.25], ...

'Box', 'on');

plot(ax_small, x2, y12, x2, y22)

annotation(fig, 'rectangle', [0.425 0.368 0.017 0.017], ...

'LineWidth', 1);

annotation(fig, 'arrow', [0.421 0.382], [0.395 0.507], ...

'LineWidth',1,'HeadStyle','plain');

##### 2 Comments

Ameer Hamza
on 1 May 2020

### More Answers (1)

John D'Errico
on 1 May 2020

Edited: John D'Errico
on 1 May 2020

There really is little way to visualize the difference between two curves that are so close together that they overlay completely on top of each other. That is, if the two curve are so close together that the width of the most narrow line possible on a monitor or your printer shows no difference, what can you do?

Perhaps an example or two will help, and I can show some things you might try.

y1 = @(x) 2 + 3*x + x.^2

y2 = @(x) 2.005 + 3.002*x + 0.999*x.^2

H1 = fplot(y1);

hold on

H2 = fplot(y2);

legend

Yes, you can use different colors. but if they over lay each other so closely, nothing will really help.

H2.LineWidth = 2;

H2.LineStyle = '--';

You can use two lines of different width, in different colors, where one of the lines is made intermittent, as I did in this ssecond figure. At least there it will become clear they are virtually overlaid.

But if you want to truly show they are different, then you may need to focus on the difference.

Hdiff = fplot(@(x) y2(x) - y1(x));

xlabel X

ylabel 'y2(x) - y1(x)'

grid on

legend

You can do that as a separate figure, or you can even inset it as Ameer did very nicely in the main figure.

My point is a picture paints different images, it teaches different things, depending on how you draw that picture. If you want to focus the attention of the reader on the idea that both lines are virtually identical, then you show them as overlapping so perfectly that one cannot see the difference between the lines. If you want to focus the attention to the difference between the curves, then plotting the difference, AS a difference will draw the focus to that aspect. Make sure you point out the small scaling on the y axis in the difference plot.

If you want to focus the attention of the person to both aspects, then plot both figures. You can do that as separate figures, or overlay the figures.

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!