fangjinSGG的个人博客分享 http://blog.sciencenet.cn/u/fangjinSGG

博文

matlab绘图的N个技巧

已有 4781 次阅读 2017-8-7 13:52 |个人分类:matlab|系统分类:科研笔记

①坐标轴位置设置

'YAxisLocation'属性设置为'right'得到双y轴。(属性值可选'left'或'right',表示将y轴放置于图形左侧或右侧)

'XAxisLocation'属性值可选'bottom'或'top',表示将x轴放置于图形下方或上方

②坐标轴刻度标注设置为字符串

通过更改xTickLabel参数进行设置(x代表X、Y、Z或其中之一,下同),xTickLabelRotation设置标注的方位

e.g.

set(gca,'XTickLabel',{'China','Japan','South Korea','Russia','Mongolia','UK'},'XTickLabelRotation',30)

另,xTickLabel设置为'',即仅仅保留坐标刻度,将坐标标签置为空。

③图例设置

1、显示特定图形的图例

legend(entries,'string1','string2',...'stringN');

e.g.

x=linspace(0,3*pi);

y1=sin(x);

y2=sin(x-pi/4);

y3=sin(x-pi/2);

y4=sin(x-3*pi/4);

y5=sin(x-pi);

h=plot(x,y1,x,y2,x,y3,x,y4,x,y5);

legend(h([2 5]),{'sin(itxrm-pi/4)','sin(itxrm-pi)','FontName','times','EdgeColor','k'});

%仅显示y2和y5图形的图例


2、图例位置

h11=legend({'sin(itxrm)','sin(itxrm-pi/4)','sin(itxrm-pi/2)','sin(itxrm-3pi/4)','sin(itxrm-pi)'},'FontName','times',...

   'EdgeColor','k','Location','northoutside','Orientation','horizental');

%定义图例位于正上方,水平排列

%Location的属性值有:图形内部east/west/north/south/southeast/southwest/northeast/northwest

                                    图形外部上述8个方向(分别加后缀outside

                                    内部最佳(best)、外部最佳(bestoutside)、无规定(none)

p11=get(h11,'Pos');p11([1 2])=[0.12 0.92];set(h11,'Pos',p11);

%由于图例过长,再次修正图例位置






https://blog.sciencenet.cn/blog-3318729-1069984.html

上一篇:matlab支持的TeX
下一篇:matlab设置数据的显示精度
收藏 IP: 223.73.86.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-28 13:54

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部