- 积分
- 14
- 注册时间
- 2003-3-3
- 仿真币
-
- 最后登录
- 1970-1-1
|
本帖最后由 messenger 于 2009-11-28 00:36 编辑
在绘图时,如果XTickLabel的字符串过长,会导致多个ticklabel重叠。一般情况下,label是可以通过属性设置其旋转的,但是,ticklabel在axis属性对话框中通过设置style只能设置FontSize和FontWeight等属性,并不能旋转。
解决方法是,通过set(h,'XTickLabel',[])命令将原来的ticklabel去掉,然后用text命令添加新的ticklabel并通过设置'Rotation'属性将其旋转。
例如:
- % 绘图,其中X轴代表月
- x = 1:12;
- y = 10*rand(1,length(x));
- h = plot(x,y,'+');
- % Remove the default labels
- set(gca,'XTickLabel','')
- % 设定X轴刻度的位置,以使其与标定的月份对应
- Xt = 1:2:11;
- Xl = [1 12];
- set(gca,'XTick',Xt,'XLim',Xl);
- % 加入文本标签
- months = ['Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'];
- ax = axis; % Current axis limits
- axis(axis); % Set the axis limit modes (e.g. XLimMode) to manual
- Yl = ax(3:4); % Y-axis limits
- t = text(Xt,Yl(1)*ones(1,length(Xt)),months(1:2:12);
- set(t,'HorizontalAlignment','right','VerticalAlignment','top', 'Rotation',45);
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
评分
-
1
查看全部评分
-
|