您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:matlab xlabel位置的设置方式

51自学网 2021-10-30 22:39:31
  python
这篇教程matlab xlabel位置的设置方式写得很实用,希望能帮到您。
xlabel(‘time',‘FontSize',12);

如果没有设置位置,默认是在中间

在xlabel中也有position用法

xlabel(‘time',‘position',[900,1870],‘FontSize',12);

此时‘time'在你设置的位置

还有一种用法是类似图像的用法

pos=axis;%取得当前坐标轴的范围,即[xmin xmax ymin ymax]xlabel(‘time',‘FontSize',12, ‘Position',[pos(2) pos(3)])x=0:pi/50:2*pi;y=sin(x);plot(x,y);pos=axis;%取得当前坐标轴的范围,即[xmin xmax ymin ymax]xlabel('x轴','position',[pos(2) 1.15*pos(3)]);%设置x轴标签的文本在图的右下方,1.15这个值根据自己的需要可以调整形成的图

补充:Matlab作图实例——xlabel,ylabel,title,text,plot,patch,datetime等的应用

做线性图,并用变量标记每个点

所用数据如下:

代码如下:

clearclcformat compactformat shortG T = readtable('repayment_schedule.xlsx','ReadVariableNames',true)T.time=datetime(datestr(T.time,'yyyy.mm.dd'),'InputFormat','yyyy.MM.dd',...    'format','yyyy.MM.dd')p=plot(T.time,T.m_per_month,T.time,T.m_residue)p(1).Marker='o'p(2).Marker='*'box off%让y轴不用科学计数法显示h=gcay_val=h.YTicky_str=string(y_val) %等价于y_str=num2str(y_val')h.YTickLabel=y_str%横轴日期显示设置h.XTick=T.timextickangle(45) %让x轴的标签逆时针旋转45度%画垂直虚线hold onp1=plot([datetime(2018,11,20) datetime(2018,11,20)],...    [0 30830],'Color',[0.6 0.6 0.6],'LineStyle','--')p2=plot([datetime(2018,12,20) datetime(2018,12,20)],...    [0 26434],'Color',[0.6 0.6 0.6],'LineStyle','--')p3=plot([datetime(2019,01,20) datetime(2019,01,20)],...    [0 22038],'Color',[0.6 0.6 0.6],'LineStyle','--')p4=plot([datetime(2019,02,20) datetime(2019,02,20)],...    [0 17641],'Color',[0.6 0.6 0.6],'LineStyle','--')p5=plot([datetime(2019,03,20) datetime(2019,03,20)],...    [0 13245],'Color',[0.6 0.6 0.6],'LineStyle','--')p6=plot([datetime(2019,04,20) datetime(2019,04,20)],...    [0 8849],'Color',[0.6 0.6 0.6],'LineStyle','--')p7=plot([datetime(2019,05,20) datetime(2019,05,20)],...    [0 4452.8],'Color',[0.6 0.6 0.6],'LineStyle','--')hold off%标注每个点str1=string(T.m_per_month)str2=string(T.m_residue)text(T.time,T.m_per_month-1200,str1,'Color',[0 0.447 0.741],...    'HorizontalAlignment','center')text(datetime(datenum(T.time)+2,'ConvertFrom','datenum'),...    T.m_residue+1100,str2,...    'Color',[0.85 0.325 0.098],...    'HorizontalAlignment','left')%图例legend([p(1) p(2)],{'每月还款金额','每月还款后剩余总本息'},...    'Location','northeast','NumColumns',1)%各个标题xlabel('还款时间')ylabel('还款金额')title({'GGG还款计划';'2018.12.20-2019.06.20'})print('GGG还款计划','-dpdf')%将数据再写入excel% writetable(T,'test.xlsx','WriteVariableNames',true)

做出的图如下:

画线形函数图,填充一部分并画网格

相应代码为:

%填充并画网格clearclcv1 = [0 0; 4 0; 4 4;0 4];f1 = [1 2 3 4];figurepatch('Faces',f1,'Vertices',v1,...    'EdgeColor',[0.75 0.75 0.75],'FaceColor',[0.75 0.75 0.75]);g=gcag.XTick=[0:4]g.YTick=[0:4]g.XLim=[0 4.5]g.YLim=[0 4.5]grid ong.Layer = 'top';g.GridColor=[1 1 1]g.GridLineStyle='--'g.GridAlpha = 1axis square%挖洞v2 = [1 1;2 1;2 2;1 2];f2 = [1 2 3 4];patch('Faces',f2,'Vertices',v2,...    'EdgeColor',[0.75 0.75 0.75],'FaceColor',[1 1 1]);%画函数图hold onf1=@(t) 4*t-4f2=@(t) 0.25*t+1f1p=fplot(f1,[1 2],'k','LineWidth',1,'DisplayName','X的策略')f2p=fplot(f2,[0 4],'--k','LineWidth',1,'DisplayName','Y的策略')xlabel('X的策略')ylabel('Y的策略')legend([f1p f2p],{},'NumColumns',2,'FontSize',10)%导出为PDF% saveas(gcf,'qiyan.pdf')print('qiyan','-dpdf')

做出的图如下

以上为个人经验,希望能给大家一个参考,也希望大家多多支持51zixue.net。


浏览器常用基本操作之python3+selenium4自动化测试(基础篇3)
python 如何设置柱状图参数
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。