multiple y axes, one x axis

조회 수: 3 (최근 30일)
androSLO
androSLO 2014년 1월 19일
댓글: Carlos Quispe Galdos 2022년 9월 30일
Hello, I want to know how to do three y axis one next to one on left side with space.. My function and i want it that is everything on left side on y axis.
clc
clear all
close all
x=[5.93 5.65 4.91 4.28 3.77 3.25];
y1=[10.72 10.15 8.76 7.61 6.68 5.76];
y2=[62.5 50 41.25 31.25 25 17.5];
y3=[4.661 4.413 3.809 3.309 2.904 2.504];
figure;
ax1 = gca;
get(ax1,'Position')
pos_ax1 = get(ax1,'Position');
set(ax1,'XColor','k',...
'YColor','b',...
'YLim',[0,12],...
'YTick',[0:1:12]);
ylabel('U_1_K [V]')
xlabel('I_1_K [A]')
line(x, y1, 'Color', 'b', 'LineStyle', '-', 'Marker', '.', 'Parent', ax1)
grid on
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','bottom',...
'YAxisLocation','left',...
'Color','none',...
'XColor','k',...
'YColor','r',...
'YLim',[0,70],...
'YTick',[0:5:70],...
'XTick',[],'XTickLabel',[]);
ylabel('P_1_K [W]')
pos_ax2=pos_ax1-1;
line(x, y2, 'Color', 'r', 'LineStyle', '-', 'Marker', '.', 'Parent', ax2)
ax3 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','bottom',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k',...
'YColor','magenta',...
'YLim',[0,5],...
'YTick',[0:0.5:5],...
'XTick',[],'XTickLabel',[]);
ylabel('u_K [%]')
line(x, y3, 'Color', 'g', 'LineStyle', '-', 'Marker', '.', 'Parent', ax3)
title('Prikaz merilnih rezultatov')
%
%figure 2
I_n = 5.435;
U_1_k=interp1(x,y1,I_n)
P_1_k=interp1(x,y2,I_n)
Thanks :)

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 19일
편집: Azzi Abdelmalek 2014년 1월 20일
Edit
x=0:0.5:10;
y1=0.1*sin(0.1*x);
y2=0.1*cos(0.1*x);
y3=0.1*cos(0.2*x);
%--------------------------------------------------------------------
xlab='time' % x-axis title
pas=8; % Number of ticks per axe
tail=8; % font size
%----------------markers and color/graph----------------------------------
mark1='d',
c1='k'
mark2='<',
c2='b'
mark3='s',
c3='r'
%---------font name and size---------------------------------------------
fontname='courrier'
fontsize=9.2;
fontsize_ax=8;
% -----------your legend names--------------------------------------------
param1='leg1',
param2='leg2',
param3='leg3',
%-----------------y-axis titles----------------------------------------
paramm1='y1',
paramm2='y2',
paramm3='y3',
%----------------------------------------------plot y1---------------------
plot(x,y1,c1)
ax1=gca;
set(gcf,'position',[100 100 1300 550])
line(x,y1,'color',c1,'Marker',mark1,'LineStyle','none','Markersize',tail,'parent',ax1);
set(ax1,'Ylim',[min(y1) max(y1)],'Xlim',[0 max(x)]);
ylabel(paramm1)
xlabel(xlab)
set(ax1,'position',[0.16 0.11 0.73 0.8],'fontsize',fontsize_ax,'Ycolor',c1)
pos=double(get(ax1,'position'))
%----------------------------------------------plot y2---------------------
ax2=axes('position',pos, 'XAxisLocation','bottom','YAxisLocation','left', 'Color','none', 'XColor',c2,'YColor',c2);
plot(x,y2,c2);
line(x,y2,'color',c2,'Marker',mark2,'LineStyle','none','Markersize',tail,'parent',ax2);
set(ax2,'Ylim',[min(y2) max(y2)],'Xlim',[0 max(x)],'Visible','off')
%----------------------------------------------plot y3---------------------
axe3=axes('position',pos, 'XAxisLocation','bottom','YAxisLocation','left','Color','none', 'XColor',c2,'YColor',c2);
plot(x,y3,c3);
line(x,y3,'color',c3,'Marker',mark3,'LineStyle','none','Markersize',tail,'parent',axe3);
set(axe3,'Ylim',[min(y3) max(y3)],'Xlim',[0 max(x)],'Visible','off')
%---------------------------------------------------------ax12-------------
pos12=[0.11 pos(2) 0.001 pos(4)]
axe12=axes('position',pos12,'XAxisLocation','top','YAxisLocation','right',...
'Color','none','fontsize',fontsize_ax, 'XColor',c2,'YColor',c2);
set(get(axe12,'XLabel'),'String',strvcat(' ',paramm2),'Fontname',fontname,'Fontsize',fontsize);
set(axe12,'Ylim',[min(y2) max(y2)])
inc2=abs(max(y2)-min(y2))/pas;
my=min(y2):inc2:max(y2);
set(axe12,'Ytick',my)
%---------------------------------------------------------ax13-------------
pos13=[0.07 pos(2) 0.001 pos(4)]
axe13=axes('position',pos13, 'XAxisLocation','top','YAxisLocation','right',...
'Color','none','fontsize',fontsize_ax, 'XColor',c3,'YColor',c3);
set(get(axe13,'XLabel'),'String',strvcat(' ',paramm3),'Fontname',fontname,'Fontsize',fontsize)
set(axe13,'Ylim',[min(y3) max(y3)])
inc3=(max(y3)-min(y3))/pas;
my=min(y3):inc3:max(y3);
set(axe13,'Ytick',my)
%------------------------------------------------legend-------------------
ax20=axes('position',pos, 'Color','none')
line(-100,100,'color',c1,'Marker',mark1,'LineStyle','-','markerfacecolor',c1,'Markersize',tail,'parent',ax20);
hold on;line(-100,100,'color',c2,'Marker',mark2,'LineStyle','-','markerfacecolor',c2,'Markersize',tail,'parent',ax20);
hold on;line(-100,100,'color',c3,'Marker',mark3,'LineStyle','-','markerfacecolor',c3,'Markersize',tail,'parent',ax20);
set(ax20,'Xlim',[0 1]);
set(ax20,'visible','off');
grid(ax1);
name={param1;param2;param3}
hleg=legend(ax20,name)
title(ax1,'figure1')
  댓글 수: 7
androSLO
androSLO 2014년 1월 20일
Yes i figure it out everything now :) Finished :)Here is result:
Thank you all for help :)
Carlos Quispe Galdos
Carlos Quispe Galdos 2022년 9월 30일
This is extremely clever! thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 1월 19일
Adapt this code supplied by the Laura at Mathworks: http://www.mathworks.com/matlabcentral/fileexchange/39595-multiplotyyy
  댓글 수: 4
androSLO
androSLO 2014년 1월 19일
Ok, I am sorry. But can somebody tell me where to put that code into it that it will work?
Image Analyst
Image Analyst 2014년 1월 19일
Put it there somewhere between the first line and the last line. I think you're a smart enough engineer to figure it out. Sorry but I don't know the details of her code, and don't have the time to do it all for you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by