Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
combine plot and subplot

Subject: combine plot and subplot

From: radar

Date: 4 Dec, 2010 18:14:10

Message: 1 of 6

I need this code below to be a subplot in a figure. I have been unsuccessful in attempting to combine this with another plot. How can I do this? Thanks in advance.

figure
[ax,h1,h2] = plotyy(x,dd,x,ds);

axes(ax(1));
hold on;
stem(nd,'Marker','none','LineWidth',0.1,'DisplayName','nd');
set(ax(1),'ylim',[-120 120])

axes(ax(2));
hold on;
plot(x,fsh);
set(ax(2),'ylim',[-1.2 1.2])

Subject: combine plot and subplot

From: Matt Fig

Date: 4 Dec, 2010 18:31:05

Message: 2 of 6

Have you tried to use the SUBPLOT command? If you have, what does it not do, specifically, that you need it to do?

Subject: combine plot and subplot

From: ImageAnalyst

Date: 4 Dec, 2010 18:55:57

Message: 3 of 6

On Dec 4, 1:14 pm, radar <a...@tds.net> wrote:
> I need this code below to be a subplot in a figure. ......
-----------------------------------
It doesn't appear that you used subplot. Try this demo:

%----- Initializing steps -----
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
        cd(fileparts(which(mfilename)));
end

% Plot #1
data1 = 240 * rand(10, 1) - 120;
subplot(2, 1, 1);
plot(data1, 'b-', 'LineWidth', 2);
title('data1', 'FontSize', fontSize);
ylim([-120 120]);

% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));

% Plot #2
data2 = rand(20, 1);
subplot(2, 2, 3);
plot(data2, 'r-', 'LineWidth', 2);
title('data2', 'FontSize', fontSize);

% Plot #3
data3 = rand(20, 1);
subplot(2, 2, 4);
plot(data3, 'g-', 'LineWidth', 2);
title('data3', 'FontSize', fontSize);

Subject: combine plot and subplot

From: radar

Date: 4 Dec, 2010 20:28:18

Message: 4 of 6

Thanks for your reply.

Yes, I did try subplot, but it must have been incorrect since it changed my stem graph back to a line graph.

There's another post with an example to try. I'll try to combine the example with my code.

Subject: combine plot and subplot

From: radar

Date: 4 Dec, 2010 20:29:49

Message: 5 of 6

Thanks for your reply. I did try subplot, but probably incorrectly since it changed my stem graph to a line graph.

I'll try and combine your example with my code. Thanks.

Subject: combine plot and subplot

From: radar

Date: 4 Dec, 2010 20:57:28

Message: 6 of 6

Thanks much! Your example was exactly what I needed.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us