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:
3 Y axes wih 4 variable

Subject: 3 Y axes wih 4 variable

From: Murat

Date: 20 Apr, 2013 07:24:08

Message: 1 of 10

Hi. I am new in Matlab and i have a problem having plotting 3 'Y' axes with one of the Y axes are common with two variable. it's like 4 variable as in the image. How can i get the true code? Please help me out.

http://img401.imageshack.us/img401/1750/3yaxeswith2common.png

Subject: 3 Y axes wih 4 variable

From: dpb

Date: 20 Apr, 2013 14:06:57

Message: 2 of 10

On 4/20/2013 2:24 AM, Murat wrote:
> Hi. I am new in Matlab and i have a problem having plotting 3 'Y' axes
> with one of the Y axes are common with two variable. it's like 4
> variable as in the image. How can i get the true code? Please help me out.
> http://img401.imageshack.us/img401/1750/3yaxeswith2common.png

See doc under 'Graphics -- Objects -- Axes Properties' there's a topic
titled "Using Multiple X= and Y-Axes"

 From its example modified slightly...

x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
x2 = [1:.2:20];
y2 = x2.^2./x2.^3;

 >> hl1 = line(x1,y1,'Color','r');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')

pos_ax1 = get(ax1,'Position'); % get the position vector 1st axis
% set the left position for another; make width so right sides match...
pos_ax2=pos_ax1; pos_ax2(1)=0.25;
pos_ax2(3)=pos_ax1(3)+pos_ax1(1)-pos_ax2(1);
% Now add another...
ax2 = axes('Position',pos_ax2,...
            'XAxisLocation','bottom',...
            'YAxisLocation','left',...
            'Color','none',...
            'XColor','k','YColor','k');


Salt to suit...

--

Subject: 3 Y axes wih 4 variable

From: Murat

Date: 21 Apr, 2013 08:22:10

Message: 3 of 10

dpb <none@non.net> wrote in message <kku7ds$lbc$1@speranza.aioe.org>...
> On 4/20/2013 2:24 AM, Murat wrote:
> > Hi. I am new in Matlab and i have a problem having plotting 3 'Y' axes
> > with one of the Y axes are common with two variable. it's like 4
> > variable as in the image. How can i get the true code? Please help me out.
> > http://img401.imageshack.us/img401/1750/3yaxeswith2common.png
>
> See doc under 'Graphics -- Objects -- Axes Properties' there's a topic
> titled "Using Multiple X= and Y-Axes"
>
> From its example modified slightly...
>
> x1 = [0:.1:40];
> y1 = 4.*cos(x1)./(x1+2);
> x2 = [1:.2:20];
> y2 = x2.^2./x2.^3;
>
> >> hl1 = line(x1,y1,'Color','r');
> ax1 = gca;
> set(ax1,'XColor','r','YColor','r')
>
> pos_ax1 = get(ax1,'Position'); % get the position vector 1st axis
> % set the left position for another; make width so right sides match...
> pos_ax2=pos_ax1; pos_ax2(1)=0.25;
> pos_ax2(3)=pos_ax1(3)+pos_ax1(1)-pos_ax2(1);
> % Now add another...
> ax2 = axes('Position',pos_ax2,...
> 'XAxisLocation','bottom',...
> 'YAxisLocation','left',...
> 'Color','none',...
> 'XColor','k','YColor','k');
>
>
> Salt to suit...
>
> --

Thank you very much for your attention.
i solved this problem with plot4y in file exchange page.

Subject: 3 Y axes wih 4 variable

From: Murat

Date: 23 Apr, 2013 11:16:07

Message: 4 of 10

still i couldn't get the what i want. i tried plotyyy , plot4y and after i showed to my teacher he said the curves must be smooth. when i looked for the smooth in plotting 4 'Y' axis i couldn't find any useful thing. and now i looked the adding new plots. but now the axis are on the left side of the original Y axis. please someone help me for this thing. here is a code for plotting 3 Y axis. I want to add 1 Y axis BUT it's the same name as one of the Y axis like in the figure ; http://img401.imageshack.us/img401/1750/3yaxeswith2common.png

%# Some sample data:
x = 0:20;
N = numel(x);
y1 = rand(1,N);
y2 = 5.*rand(1,N)+5;
y3 = 50.*rand(1,N)-50;
y4 = 500.*rand(1,N)+50;


%# Some initial computations:
axesPosition = [110 40 200 200]; %# Axes position, in pixels
yWidth = 30; %# y axes spacing, in pixels
xLimit = [min(x) max(x)]; %# Range of x values
xOffset = -yWidth*diff(xLimit)/axesPosition(3);

%# Create the figure and axes:
figure('Units','pixels','Position',[200 200 330 260]);
h1 = axes('Units','pixels','Position',axesPosition,...
          'Color','w','XColor','k','YColor','r',...
          'XLim',xLimit,'YLim',[0 1],'NextPlot','add');
h2 = axes('Units','pixels','Position',axesPosition+yWidth.*[-1 0 1 0],...
          'Color','none','XColor','k','YColor','m',...
          'XLim',xLimit+[xOffset 0],'YLim',[0 10],...
          'XTick',[],'XTickLabel',[],'NextPlot','add');
h3 = axes('Units','pixels','Position',axesPosition+yWidth.*[-2 0 2 0],...
          'Color','none','XColor','k','YColor','b',...
          'XLim',xLimit+[2*xOffset 0],'YLim',[-50 50],...
          'XTick',[],'XTickLabel',[],'NextPlot','add');
xlabel(h1,'time');
ylabel(h3,'values');

%# Plot the data:
plot(h1,x,y1,'r');
plot(h2,x,y2,'m');
plot(h3,x,y3,'b');

Subject: 3 Y axes wih 4 variable

From: Murat

Date: 23 Apr, 2013 16:18:07

Message: 5 of 10

i got some progress in my programme. now i have a question ; how can i get the curves smooth in this codes? ;

c = [0.008 0.009 0.01 0.01179 0.013 0.015 0.02 0.025 0.03 0.0362 0.04 0.045] ;
h0 = [0.0048 0.00495 0.0049 0.00495 0.00481 0.0048 0.0048 0.00475 0.0042 0.00398 0.004 0.00405];
Q = [1275 1501.9 1725 2100 2388.8 2840.6 3975 5081.3 6198.8 7602 8445 9686];
Qs = [701.25 901.14 1069.5 1491 1767.712 2244.074 3418.5 4522.357 5640.908 7069.86 7938.3 9201.7];
f = [0.00453 0.0042 0.0037 0.0035 0.00325 0.003 0.003 0.0024 0.0022 0.00211 0.00213 0.0021];

%# Some initial computations:
axesPosition = [200 40 1000 500]; %# Axes position, in pixels
yWidth = 30; %# y axes spacing, in pixels
xLimit = [min(c) max(c)]; %# Range of x values
xOffset = -yWidth*diff(xLimit)/axesPosition(3);

%# Create the figure and axes:
figure('Units','pixels','Position',[300 300 750 750]);
h1 = axes('Units','pixels','Position',axesPosition,...
          'Color','w','XColor','k','YColor','r',...
          'XLim',xLimit,'NextPlot','add');
h2 = axes('Units','pixels','Position',axesPosition+yWidth.*[-1.25 0 1 0],...
          'Color','none','XColor','k','YColor','c',...
          'XLim',xLimit+[1.25*xOffset 0],...
          'XTick',[],'XTickLabel',[],...
          'NextPlot','add');
h3 = axes('Units','pixels','Position',axesPosition+yWidth.*[-2.5 0 2 0],...
          'Color','none','XColor','k','YColor','g',...
          'XLim',xLimit+[2.5*xOffset 0],...
          'XTick',[],'XTickLabel',[],'NextPlot','add');
xlabel(h1,'time');
ylabel(h3,'values');

%# Plot the data:
plot(h1,c,h0,'r');
plot(h2,c,Q,'c');
plot(h2,c,Qs,'b');
plot(h3,c,f,'g')


            %'XAxisLocation','bottom',...
            %'YAxisLocation','left',...

Subject: 3 Y axes wih 4 variable

From: dpb

Date: 23 Apr, 2013 21:12:26

Message: 6 of 10

On 4/23/2013 11:18 AM, Murat wrote:
> i got some progress in my programme. now i have a question ; how can i
> get the curves smooth in this codes? ;
>
...

Well, Q and Qs look pretty smooth to me as is...h0 and f not so much.

I guess the answer to the question depends on what you think "smooth"
is--you might start w/ the BasicFitting toolbox and see what you think
of its selection of splines.

--

Subject: 3 Y axes wih 4 variable

From: Murat

Date: 24 Apr, 2013 03:19:07

Message: 7 of 10

dpb <none@non.net> wrote in message <kl6tg0$pt9$1@speranza.aioe.org>...
> On 4/23/2013 11:18 AM, Murat wrote:
> > i got some progress in my programme. now i have a question ; how can i
> > get the curves smooth in this codes? ;
> >
> ...
>
> Well, Q and Qs look pretty smooth to me as is...h0 and f not so much.
>
> I guess the answer to the question depends on what you think "smooth"
> is--you might start w/ the BasicFitting toolbox and see what you think
> of its selection of splines.
>
> --
>



thank you for your reply

i mean as in the image h0 and f has no edge. they are like curves as in the x^2. am i clear now?

http://img401.imageshack.us/img401/1750/3yaxeswith2common.png

Subject: 3 Y axes wih 4 variable

From: dpb

Date: 24 Apr, 2013 05:42:47

Message: 8 of 10

On 4/23/2013 10:19 PM, Murat wrote:
> dpb <none@non.net> wrote in message <kl6tg0$pt9$1@speranza.aioe.org>...
>> On 4/23/2013 11:18 AM, Murat wrote:
>> > i got some progress in my programme. now i have a question ; how can i
>> > get the curves smooth in this codes? ;
>> >
>> ...
>>
>> Well, Q and Qs look pretty smooth to me as is...h0 and f not so much.
>>
>> I guess the answer to the question depends on what you think "smooth"
>> is--you might start w/ the BasicFitting toolbox and see what you think
>> of its selection of splines.
>>
>> --
>>
>
>
>
> thank you for your reply
>
> i mean as in the image h0 and f has no edge. they are like curves as in
> the x^2. am i clear now?
> http://img401.imageshack.us/img401/1750/3yaxeswith2common.png

Well, they were fortunate to have data points that were/are much
smoother. You'll have to smudge your data or use a fitted functional
smoothing function as suggested -- but it won't then represent the
actual datapoints you have as well.

That's the point was making before--you'll have to decide what's more
important--beauty or the data. Be careful if it's experimental data of
misrepresenting reality if this is anything other than an exercise, however.

--

Subject: 3 Y axes wih 4 variable

From: Murat

Date: 24 Apr, 2013 09:51:08

Message: 9 of 10


> Well, they were fortunate to have data points that were/are much
> smoother. You'll have to smudge your data or use a fitted functional
> smoothing function as suggested -- but it won't then represent the
> actual datapoints you have as well.
>
> That's the point was making before--you'll have to decide what's more
> important--beauty or the data. Be careful if it's experimental data of
> misrepresenting reality if this is anything other than an exercise, however.
>
> --

in the figure editting there is Tools>Basic Fitting. if i select data1 and make it spline interpolant then it's what exactly i want. BUT if i try to make it for data2 then Data1 disappears. It's why i am asking if there is a command for this codes? i tried
[xx,yy]=smoothline(x,y)
plot(xx,yy)
but it didn't work. so is there any other solution?

Subject: 3 Y axes wih 4 variable

From: dpb

Date: 24 Apr, 2013 13:28:02

Message: 10 of 10

On 4/24/2013 4:51 AM, Murat wrote:
...

> in the figure editting there is Tools>Basic Fitting. if i select data1
> and make it spline interpolant then it's what exactly i want. BUT if i
> try to make it for data2 then Data1 disappears. It's why i am asking if
> there is a command for this codes? i tried [xx,yy]=smoothline(x,y)
> plot(xx,yy)
> but it didn't work. so is there any other solution?

Read the help in the toolset -- you can either manually evaluate the fit
at chosen points and save to workspace for each dataset and add that to
the plot or do what it does directly via

doc spline % and friends...

--

Tags for 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