当前位置:网站首页>matlab plotyy 坐标轴设置,[转载]Matlab plotyy画双纵坐标图实例[通俗易懂]
matlab plotyy 坐标轴设置,[转载]Matlab plotyy画双纵坐标图实例[通俗易懂]
2022-06-28 12:55:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
Matlab plotyy画双纵坐标图实例
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:右边用蓝色圈起来的tick能去掉吗?由于用plotyy画图,为了使图尽量地显示出来,用了set(AX(1),’YLimMode’,’auto’),但这样可能会导致左边AX(1)和右边AX(2)的tick的间距不一样,影响美观。或者说能不能使plotyy画出的图两边的tick间距是一样的,这样在图形右边的tick就会重合在一起.
A:如果只是想让plotyy的图美一些,可以使用其如下形式的调用方式:
[AX,H1,H2] = plotyy(…)
其中AX(2)就是右边Axes对象的句柄,拿到它以后就可以set或者get来处理了,也可以把其ytick关掉。
A:也可以用line语句来画,就没有左边和上边的线了。
Q:plotyy(X1,Y1,X2,Y2,FUN1,FUN2),FUN1和FUN2应该怎么写?
A:这两个FUN代表plotyy不一定要用两个plot,比如下面的例子,一条曲线用plot,一条用semilogy
x1=1:0.1:100;
x2=x1;
y1=x1;
y2=x2.^3;
plotyy(x1,y1,x2,y2,@plot,@semilogy)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MATLAB画双纵坐标
具有两个纵坐标标度的图形
在MATLAB中,如果需要绘制出具有不同纵坐标标度的两个图形,可以使用plotyy绘图函数。调用格式为:
plotyy(x1,y1,x2,y2)
其中x1,y1对应一条曲线,x2,y2对应另一条曲线。横坐标的标度相同,纵坐标有两个,左纵坐标用于x1,y1数据对,右纵坐标用于x2,y2数据对。
双y轴坐标可以用plotyy(x,y1,x,y2)来实现
双x坐标可以用
set(gca,’xaxislocation’,’bottom’,’xticklabel’,{‘0′,’1′,’2′,’3′,’4’})
(假设x轴的标注为1,2,3,4)
set(gca,’xaxislocation’,’top’,’xticklabel’,{‘0′,’1′,’2′,’3′,’4’})
进行相应的设置
【 * 例 10.7.3 -1 】制作一个双坐标系用来表现高压和低温两个不同量的过渡过程。
tp=(0:100)/100*5;yp=8+4*(1-exp(-0.8*tp).*cos(3*tp)); % 压力数据
tt=(0:500)/500*40;yt=120+40*(1-exp(-0.05*tt).*cos(tt)); %
温度数据
% 产生双坐标系图形
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’,’ 时间 /rightarrow (分) ‘)
set(get(h_ap,’Ylabel’),’String’,’ 压力 /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{ 隶书 } 时间
/rightarrow (分) ‘)
set(get(h_at,’Ylabel’),’String’,’ ( {/circ}C )/fontsize{15}
/leftarrow /fontname{ 隶书 } 零下温度 ‘)
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>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
实例(已验证):
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]);
尚存在问题:这种设置方法,对各个轴的最小刻度单位可以设置,但是刻度范围(x取(0~7),y1取(-1~1))不能设置。
2010-12-23修改
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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’) %标注两条线
legend(‘boxoff’)
% box off
set(ax(:),’Ycolor’,’k’) %设定两个Y轴的颜色为黑色
set(ax(1),’ytick’,[0:10000:100000]); %设置y轴间隔
set(ax(2),’ytick’,[0:0.1:1.5])
set(ax,’xlim’,[1 12]) % 设置x轴范围
hold on
scatter(ax(1),4,22900,’r*’)
axes(ax(2));
hold on
scatter(4,1.264,’ro’)
2011年4月22日新增
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/150679.html原文链接:https://javaforall.cn
边栏推荐
- 一种跳板机的实现思路
- Jerry's wif interferes with Bluetooth [chapter]
- 微服务稳定性保障
- ASP. NET CORE Study09
- ASP. NET CORE Study11
- From simplekv to redis
- go template with... End traversal usage
- The press conference of Tencent cloud Database & CSDN engineer's ability lightweight certification is coming
- ASP.NET CORE Study02
- Namespace and scope
猜你喜欢

关于IP定位查询接口的测评Ⅰ

SHAREit实力出众,登陆全球 IAP 实力榜 Top7
思源官方付费同步使用指南

The paging style flex is set to be displayed at the end (even if the number of pages is longer, there will be no line breaks at the end)

《数字经济全景白皮书》消费金融数字化篇 重磅发布
![[MySQL from introduction to mastery] [advanced part] (III) creation of MySQL users_ Modification_ Delete and password settings](/img/9c/2a0eb8f5ec03aebbe231dbdb388eca.png)
[MySQL from introduction to mastery] [advanced part] (III) creation of MySQL users_ Modification_ Delete and password settings

SHAREit實力出眾,登陸全球 IAP 實力榜 Top7

求职简历的书写技巧

Matplotlib_Study01

IPETRONIK数据采集设备携手Softing Q-Vision软件致力于ADAS测试方案
随机推荐
深入理解贝叶斯定理
I ² C. SMBus, pmbus relationships
Digital twin energy system, creating a "perspective" in the low-carbon era
哪一个证券公司最好最安全 怎么办理开户最安全
Jerry's wif interferes with Bluetooth [chapter]
百度APP 基于Pipeline as Code的持续集成实践
华泰证券手机app下载 怎么办理开户最安全
如何在Microsoft Exchange 2010中安装SSL证书
Centos6.5 php+mysql MySQL library not found
Flink stream processing API collection: master all Flink stream processing technologies. Just read this article
Understand leveldb write operation
ASP.NET CORE Study08
unity发布 webgl在手机端 inputfield唤醒键盘输入
Manjaro easyconnecy error: libgtk-x11-2.0 so. 0: cannot open shared object file: No such file or directory
基础软件照搬开源不可取,自力更生才是正途
ASP. NET CORE Study04
Tencent has confirmed that QQ has stolen numbers on a large scale, iphone14 has no chance of type-C, and 5g, the fourth largest operator, has officially released numbers. Today, more big news is here
数启扬帆,智聚人才 | 腾讯云数据库 & CSDN 工程师能力轻量认证发布会重磅来袭!...
group_concat学习与配置
Deep understanding of Bayes theorem