xsticklabel_rotate parameter/value pair arguments

조회 수: 2 (최근 30일)
aine gormley
aine gormley 2018년 10월 17일
댓글: aine gormley 2018년 10월 20일
Hi, Im trying to plot the following figure, but keep getting the error about xsticklabel.
if true
>> figure;
h = bar(1:7,QIRR_srex,'hist'); hold on;
g(1) = plot(1,1, 'b', 'LineWidth',2.5); hold on;
g(2) = plot(1,1, 'g', 'LineWidth',2.5); hold on;
set(h(1),'facecolor',[0.5 0.5 1])
set(h(2),'facecolor',[0.5 1 0.5])
set(h(3),'facecolor',[1 0.5 0.5])
set(h,'edgecolor','none')
axis([0 8 0 160]);
mf_xticklabel_rotate([1:7],45,[srex_reg],'interpreter','none','Fontsize', 11, 'Fontweight', 'Bold','color', axcolor); %#ok<NBRAK>
ylabel('Q_i_r_r [mm yr^-^1]', 'Fontsize', 14, 'Fontweight', 'Bold');
legend(g, 'OBS', 'IRR', 'Location', 'SouthWest');
set(legend,'YColor','w','XColor','w', 'Fontweight', 'Bold', 'Fontsize', 11,'textcolor', axcolor);
set(gca, 'Fontsize', 14, 'Fontweight', 'Bold','Xcolor', axcolor,'Ycolor', axcolor);
export_fig text/figures_paper/figure_02 -transparent;
Error using matlab.graphics.primitive.Text/set
Invalid parameter/value pair arguments.
Error in mf_xticklabel_rotate (line 154)
set(hText,'HorizontalAlignment','right',varargin{:})
Here is also the part of xsticklabel the error refers to: xAxisLocation = get(gca, 'XAxisLocation');
xAxisLocation = get(gca, 'XAxisLocation');
if strcmp(xAxisLocation,'bottom')
set(hText,'Rotation', rot, 'HorizontalAlignment','right',varargin{:})
else
set(hText,'Rotation', rot, 'HorizontalAlignment','left',varargin{:})
end if true
I have tried multiple things like different putting in rot value directly (ie 90), but it doesnt seem to help. Please can someone help?
  댓글 수: 3
aine gormley
aine gormley 2018년 10월 17일
Hi; hereis QIRR_srex info:
% % irrigation amounts
QIRR_srex(:,1) = mf_srex(lat_mod, lon_mod, QIRR_obs, island, [], 'WNA', 'CNA', 'MED', 'WAS', 'SAS', 'SEA', 'EAS');
QIRR_srex(:,2) = mf_srex(lat_mod, lon_mod, QIRR_irr, island, [], 'WNA', 'CNA', 'MED', 'WAS', 'SAS', 'SEA', 'EAS');
QIRR_srex(:,3) = mf_srex(lat_mod, lon_mod, QIRR_ctl, island, [], 'WNA', 'CNA', 'MED', 'WAS', 'SAS', 'SEA', 'EAS');
aine gormley
aine gormley 2018년 10월 17일
Hi; here is the function of xticklabel_rotate
function hText = mf_xticklabel_rotate(XTick,rot,varargin)
%hText = xticklabel_rotate(XTick,rot,XTickLabel,varargin) Rotate XTickLabel
%
% Syntax: xticklabel_rotate
%
% Input:
% {opt} XTick - vector array of XTick positions & values (numeric)
% uses current XTick values or XTickLabel cell array by
% default (if empty)
% {opt} rot - angle of rotation in degrees, 90 by default
% {opt} XTickLabel - cell array of label strings
% {opt} [var] - "Property-value" pairs passed to text generator
% ex: 'interpreter','none'
% 'Color','m','Fontweight','bold'
%
% Output: hText - handle vector to text labels
%
% Example 1: Rotate existing XTickLabels at their current position by 90
% xticklabel_rotate
%
% Example 2: Rotate existing XTickLabels at their current position by 45 and change
% font size
% xticklabel_rotate([],45,[],'Fontsize',14)
%
% Example 3: Set the positions of the XTicks and rotate them 90
% figure; plot([1960:2004],randn(45,1)); xlim([1960 2004]);
% xticklabel_rotate([1960:2:2004]);
%
% Example 4: Use text labels at XTick positions rotated 45 without tex interpreter
% xticklabel_rotate(XTick,45,NameFields,'interpreter','none');
%
% Example 5: Use text labels rotated 90 at current positions
% xticklabel_rotate([],90,NameFields);
%
% Note : you can not RE-RUN xticklabel_rotate on the same graph.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2018년 10월 17일
Which release of MATLAB are you using? If you're using release R2014b or later there are properties that support rotated axis tick labels. If you're using release R2016b or later there are convenience functions that will make it easier to rotate the labels.
  댓글 수: 3
Steven Lord
Steven Lord 2018년 10월 17일
In that case, try just using xtickangle.
aine gormley
aine gormley 2018년 10월 20일
perfect, thank you :-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by