yyplot中的标签

时间:2015-04-29 07:58:25

标签: matlab plot matlab-figure

我的问题是,我正在创建的数字获得了“两种类型”的x-ax标签。一个是我要求的,另一个是数字,它每2个显示一次。实际上,标签和数字是重叠的。我是论坛的新手,因此它不允许我放置图片。

我使用以下方法创建了它:

Names = 1:10;

[ax,b,p] = plotyy(Names, aguaI, Names, WaterUseby10Sectors,'bar','plot');

title('Direct use and expenditure in water')

xlabel('Sector')

set(gca, 'Xtick',1:10, 'XTickLabel',{'Animal Agic','Plant agric', 'Other agric', 'Mining', 'Food industry', 'Other industries', 'Energy', 'Water', 'Retail, resta, accomm', 'Other Services'})

ylabel(ax(1),'Water use by sector (Ml)')

ylabel(ax(2),'Sectors expenditure in water (AUS$ M)')

如何从x轴中取出数字?另外,为什么图形产生x轴直到12?

enter image description here

3 个答案:

答案 0 :(得分:2)

(未经测试)这样做吗?

set ( ax(1), 'XTick', [] );

这是将第1轴的xtick设置为空 - >它应该删除与第一轴相关的数字。

答案 1 :(得分:2)

我会替换那一行:

set(gca, 'Xtick',1:10, 'XTickLabel',{'Animal Agic','Plant agric', 'Other agric', 'Mining', 'Food industry', 'Other industries', 'Energy', 'Water', 'Retail, resta, accomm', 'Other Services'})

这两行:

set(ax(1), 'Xtick',1:10, 'XTickLabel',{'Animal Agic','Plant agric', 'Other agric', 'Mining', 'Food industry', 'Other industries', 'Energy', 'Water', 'Retail, resta, accomm', 'Other Services'})
set(ax(2), 'Xtick',1:10, 'XTickLabel',{'Animal Agic','Plant agric', 'Other agric', 'Mining', 'Food industry', 'Other industries', 'Energy', 'Water', 'Retail, resta, accomm', 'Other Services'})

确保两组轴具有一致的刻度和标签。或者,您可以将其中一个设置为空,如已建议的那样。

答案 2 :(得分:0)

请检查以下代码。

clear all;

i = [1:1:27];

c = [821, 871, 895, 912, 934, 951, 964, 975, 989, 997, 1011, 1019,...
    1026, 1031, 1038, 1043, 1046, 1047, 1053, 1059, 1070, 1076, 1080,...
    1083, 1088, 1092, 1091];

e = [0.026296, 0.025658, 0.025093, 0.024575, 0.024105, 0.023696,...
    0.023335, 0.023021, 0.022759, 0.022519, 0.022226, 0.021933,...
    0.021724, 0.021555, 0.021401, 0.021283, 0.021191, 0.021110,...
    0.021020, 0.020938, 0.020840, 0.020721, 0.020635, 0.020536,...
    0.020462, 0.020387, 0.020320];

[hAx,hL1,hL2] = plotyy(i, c, i, e);
set(hAx,'xlim',[1,27]);
hL1.LineStyle = '-';
hL2.LineStyle = '--';
hL1.Color = 'r';
hL2.Color = 'b';
hL1.Marker = 'o';
hL2.Marker = '+';
xlabel('Number');

ylabel(hAx(1),'C') % left y-axis
ylabel(hAx(2),'E') % right y-axis

legend('C','E');

axis tight;
set(gca, 'xtick',1:1:27);
set(hAx(2),'Position', [0.13 0.11 0.775-.025 0.815]);

输出:

enter image description here