当前位置:网站首页>Matlab plotyy coordinate axis setting, [reprint] example of MATLAB plotyy drawing double ordinate graph [easy to understand]
Matlab plotyy coordinate axis setting, [reprint] example of MATLAB plotyy drawing double ordinate graph [easy to understand]
2022-06-28 13:05:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Matlab plotyy Example of drawing double ordinate diagram
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y2,’plot’);
set(AX(1),’XColor’,’k’,’YColor’,’b’);
set(AX(2),’XColor’,’k’,’YColor’,’r’);
HH1=get(AX(1),’Ylabel’);
set(HH1,’String’,’Left Y-axis’);
set(HH1,’color’,’b’);
HH2=get(AX(2),’Ylabel’);
set(HH2,’String’,’Right Y-axis’);
set(HH2,’color’,’r’);
set(H1,’LineStyle’,’-‘);
set(H1,’color’,’b’);
set(H2,’LineStyle’,’:’);
set(H2,’color’,’r’);
legend([H1,H2],{‘y1 = 200*exp(-0.05*x).*sin(x)’;’y2 =
0.8*exp(-0.5*x).*sin(10*x)’});
xlabel(‘Zero to 20 musec.’);
title(‘Labeling plotyy’);
Q: It's circled in blue on the right tick Can you remove it ? Because of the use of plotyy drawing , In order to make the diagram as clear as possible , It was used set(AX(1),’YLimMode’,’auto’), But this may lead to the left AX(1) And on the right AX(2) Of tick The spacing of the is different , Affect beauty . Or can you make plotyy On both sides of the picture tick The spacing is the same , So on the right side of the graph tick Will coincide .
A: If you just want plotyy The picture is more beautiful , It can be called in the following form :
[AX,H1,H2] = plotyy(…)
among AX(2) It's on the right Axes Object handle , After you get it, you can set perhaps get To deal with the , It can also be ytick Turn off the .
A: It can also be used. line Sentence to draw , There is no line on the left and top .
Q:plotyy(X1,Y1,X2,Y2,FUN1,FUN2),FUN1 and FUN2 How to write ?
A: these two items. FUN representative plotyy You don't have to use two plot, Take the following example , A curve uses plot, One for semilogy
x1=1:0.1:100;
x2=x1;
y1=x1;
y2=x2.^3;
plotyy(x1,y1,x2,y2,@plot,@semilogy)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MATLAB Draw Double ordinates
A graph with two ordinate scales
stay MATLAB in , If you need to draw two figures with different ordinate scales , have access to plotyy Plot function . The invocation format is :
plotyy(x1,y1,x2,y2)
among x1,y1 Corresponding to a curve ,x2,y2 Corresponding to another curve . The scale of the abscissa is the same , The ordinate has two , The left ordinate is used for x1,y1 Data on , The right ordinate is used for x2,y2 Data on .
double y Axis coordinates can be expressed as plotyy(x,y1,x,y2) To achieve
double x Coordinates can be used
set(gca,’xaxislocation’,’bottom’,’xticklabel’,{‘0′,’1′,’2′,’3′,’4’})
( hypothesis x The axis is marked as 1,2,3,4)
set(gca,’xaxislocation’,’top’,’xticklabel’,{‘0′,’1′,’2′,’3′,’4’})
Make the corresponding settings
【 * example 10.7.3 -1 】 A two coordinate system is made to represent the transition process of high pressure and low temperature .
tp=(0:100)/100*5;yp=8+4*(1-exp(-0.8*tp).*cos(3*tp)); % Pressure data
tt=(0:500)/500*40;yt=120+40*(1-exp(-0.05*tt).*cos(tt)); %
Temperature data
% Generate a two coordinate system graph
clf reset,h_ap=axes(‘Position’,[0.13,0.13,0.7,0.75]);
%<4>
set(h_ap,’Xcolor’,’b’,’Ycolor’,’b’,’Xlim’,[0,5],’Ylim’,[0,15]);
nx=10;ny=6; %<6>
pxtick=0:((5-0)/nx):5;pytick=0:((15-0)/ny):15;
%<7>
set(h_ap,’Xtick’,pxtick,’Ytick’,pytick,’Xgrid’,’on’,’Ygrid’,’on’)
h_linet=line(tp,yp,’Color’,’b’);
%<9>
set(get(h_ap,’Xlabel’),’String’,’ Time /rightarrow ( branch ) ‘)
set(get(h_ap,’Ylabel’),’String’,’ pressure /rightarrow(/times10 ^{5}
Pa )’)
h_at=axes(‘Position’,get(h_ap,’Position’));
%<12>
set(h_at,’Color’,’none’,’Xcolor’,’r’,’Ycolor’,’r’);
%<13>
set(h_at,’Xaxislocation’,’top’)
%<14>
set(h_at,’Yaxislocation’,’right’,’Ydir’,’rev’)
%<15>
set(get(h_at,’Xlabel’),’String’,’/fontsize{15}/fontname{ Official script } Time
/rightarrow ( branch ) ‘)
set(get(h_at,’Ylabel’),’String’,’ ( {/circ}C )/fontsize{15}
/leftarrow /fontname{ Official script } Subzero temperature ‘)
set(h_at,’Ylim’,[0,210]) %<18>
line(tt,yt,’Color’,’r’,’Parent’,h_at)
%<19>
xpm=get(h_at,’Xlim’); %<20>
txtick=xpm(1):((xpm(2)-xpm(1))/nx):xpm(2);
%<21>
tytick=0:((210-0)/ny):210;
%<22>
set(h_at,’Xtick’,txtick,’Ytick’,tytick)
%<23>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example ( Verified ):
clc;
clear all;
close all;
x=0:0.1:2*pi;
y1=sin(x);
y2=cos(x);
[AX]=plotyy(x,y1,x,y2);
set(get(gca,’xlabel’),’string’,’X-axis’);
set(get(AX(1),’Ylabel’),’string’,’left Y-axis’);
set(get(AX(2),’Ylabel’),’string’,’right Y-axis’);
set(gca,’xTick’,[0:0.5:7]);
set(AX(1),’yTick’,[-1:0.2:1]);
set(AX(2),’yTick’,[-1:0.5:1]);
There are still problems : This setting method , The minimum scale unit of each axis can be set , But the scale range (x take (0~7),y1 take (-1~1)) Cannot set .
2010-12-23 modify
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clc
clear all
close all
runoff=[10700 11400 15800 22900 43100 40700 50500 46000 41800
35000];
sed=[0.105 0.094 0.156 1.264 0.363 0.429 0.731 0.682 0.654 0.290];
m=1:10;
[ax,h1,h2]=plotyy(m,runoff,m,sed); %h– line handle
set(get(ax(1),’Ylabel’),’string’,’Runoff (m^3/s))’,’color’,’r’)
%y1
set(get(ax(2),’Ylabel’),’string’,’Sediment concentration
(kg/m^3)’,’color’,’k’) %y2
xlabel(‘Month’)
set(h1,’linestyle’,’-‘,’color’,’r’); set(h2,’linestyle’,’- -‘,’color’,’k’);
legend([h1 h2],’runoff’,’sediment concentration’) % Mark two lines
legend(‘boxoff’)
% box off
set(ax(:),’Ycolor’,’k’) % Set two Y The color of the shaft is black
set(ax(1),’ytick’,[0:10000:100000]); % Set up y Axial spacing
set(ax(2),’ytick’,[0:0.1:1.5])
set(ax,’xlim’,[1 12]) % Set up x Axis range
hold on
scatter(ax(1),4,22900,’r*’)
axes(ax(2));
hold on
scatter(4,1.264,’ro’)
2011 year 4 month 22 New day
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/150679.html Link to the original text :https://javaforall.cn
边栏推荐
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- plt.savefig()的用法以及保存路径
- Mysq 8.0 launched histogram, which greatly improved the performance!
- ASP. NET CORE Study08
- The Research Report of Analysys' 2022 China Banking privacy computing platform supplier strength matrix analysis' was officially launched
- ASP. NET CORE Study06
- 移动Web实训DAY-2
- In fact, there are a lot of MATLAB learning and use materials (many documents and videos) on the official website of MATLAB
- 深入理解贝叶斯定理
- Which securities company is the best and safest? How to open an account is the safest
猜你喜欢
随机推荐
百度APP 基于Pipeline as Code的持续集成实践
plt.savefig()的用法以及保存路径
腾讯确认QQ大规模盗号,iPhone14无缘Type-C,第四大运营商5G正式放号,今日更多大新闻在此...
mysql数据库扫盲,你真的知道什么是数据库嘛
Mysq 8.0 launched histogram, which greatly improved the performance!
flutter 系列之:flutter 中常用的 GridView layout 详解
词云的可视化设计教程
ASP. NET CORE Study09
Understand leveldb write operation
数字孪生能源系统,打造低碳时代“透视”眼
自定义MySQL连接池
[cloud native] can self-service reports and Bi do so many things?
flink核心之watermarker
求职简历的书写技巧
Evaluation of IP location query interface I
Arduino-ESP32闪存文件插件程序搭建和上传
2. 01背包问题
电驴怎么显示服务器列表,(转)如何更新电驴服务器列表(eMule Server List)
Realization of a springboard machine
Scratch travel photo album Electronic Society graphical programming scratch grade examination level 1 true questions and answers analysis June 2022









