Bea
Bea

Reputation: 13

Labels in yyplot

My problem is that the figure that I'm creating gets "two types" of x-axe labels. One is the ones that I have asked for, the other is a number, its displays it every 2. Actually, labels and numbers are overlap. I'm new to the forum, hence it does not allow me to place pictures.

I have created it using the following:

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)')

How do I take the numbers out of the x-axis? Also, why the graph is producing a x-axis until 12?

enter image description here

Upvotes: 1

Views: 211

Answers (3)

Please check the following code.

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]);

Output:

enter image description here

Upvotes: 0

am304
am304

Reputation: 13876

I would replace that line:

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

with these two lines:

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'})

To ensure both set of axes have consistent ticks and labels. Alternatively, you can set one to be empty, as already suggested.

Upvotes: 2

matlabgui
matlabgui

Reputation: 5672

(Untested) Does this do it?

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

This is setting the xtick of your 1st axes to be empty -> it should remove the numbers associated with the 1st axes.

Upvotes: 2

Related Questions