1.怎样在坐标轴上设置自定义的标签
答:set(gca,'XTickLabel',{'FD001','FD002','FD003','FD004'});% 设置其余坐标区属性
2.用text()显示plot函数的坐标点
(转:Matlab代码之plot函数的坐标点显示_横冲直撞de的博客-CSDN博客_matlab plot显示数据点)
//
clc;clear;close all;
x=1:8;
y1=x+2;
figure;subplot(1,2,1);plot(x,y2,'-*');title('图2:显示函数坐标点形式一');
xlabel('x');ylabel('y2');
str1=num2str(y2');text(x,y2,str1);
%文件名不能与matlab内置函数同名,不然运行失败。
subplot(1,2,2);plot(x,y2,'-*');title('图3:显示函数坐标点形式二');
xlabel('x');ylabel('y2');
for i=1:8
text(x(i),y2(i),['(',num2str(x(i)),',',num2str(y2(i)),')']);
end
%第二种形式的第二种表达方法
%str=[repmat('(',size(x,2),1),num2str(x') ...
%repmat(', ',size(x,2),1),num2str(y2'),repmat(')',size(x,2),1)];
%text(x,y2,cellstr(str));
3.MATLAB绘制条形图并显示数值
转自:MATLAB绘制条形图并显示数值_zhangsangood的博客-CSDN博客_matlab柱状图显示数据
x = 2012:1:2020;
y = [1, 4, 2, 8, 49, 122, 358, 859, 1477];
b = bar(x, y, 0.6) %0.6表示条形图宽度,可修改
xlabel('年份')
ylabel('数值')
set(gca,'ylim',[0,1600],'ytick',[0:200:1600]); %纵坐标数值为0到1600,每隔200显示刻度
set(gca, 'Ygrid','on'); %纵坐标刻度显示网格
xtips1 = b.XEndPoints;
ytips1 = b.YEndPoints; %获取 Bar 对象的 XEndPoints 和 YEndPoints 属性
labels1 = string(b.YData); %获取条形末端的坐标
text(xtips1,ytips1,labels1,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
%将这些坐标传递给 text 函数,并指定垂直和水平对齐方式,让值显示在条形末端上方居中处
4.Matlab 图例 位置的不同命令
Matlab位置选择
一个简单的表格是这么创建的:
转自:Matlab 图例 位置的不同命令_VS洗发水的博客-CSDN博客_matlab图例位置
设置 | 位置 |
---|---|
‘North’ | inside plot box near top |
‘South’ | inside bottom |
‘East’ | inside right |
‘West’ | inside left |
‘NorthEast’ | inside top right (default for 2-D plots) |
‘NorthWest’ | inside top left |
‘SouthEast’ | inside bottom right |
‘SouthWest’ | inside bottom left |
‘NorthOutside’ | outside plot box near top |
‘SouthOutside’ | outside bottom |
‘EastOutside’ | outside right |
‘WestOutside’ | outside left |
‘NorthEastOutside’ | outside top right (default for 3-D plots) |
‘NorthWestOutside’ | outside top left |
‘SouthEastOutside’ | outside bottom right |
‘SouthWestOutside’ | outside bottom left |
‘Best’ | least conflict with data in plot |
‘BestOutside’ | least unused space outside plot |
or reload the browserDisable in this text fieldRephraseRephrase current sentence Edit in Ginger×