mHelpMe
mHelpMe

Reputation: 6668

plotyy function showing two x-axes but only want one

I am using the plotyy function to produce the chart in the image below.

My Chart

I have two issues with this chart. First issue being having two x-axes I want the zero on the left hand side of my chart to be level with the zero on the right hand side. Is there anyway I can make this happen?

Lastly I want to put some labels on the x-axis however you can that I labels have numbers on top of them. I only want the labels to be visible which I cannot seem to do?

Below is my code.

 x_labels = data_cell(2:end, 1);
 risk_tot = cell2mat(data_cell(2:end, 2));
 risk_cont = cell2mat(data_cell(2:end, 3));

 [pp,h1,h2]=plotyy((1:length(risk_tot)),risk_tot,(1:length(risk_tot)),risk_cont,'bar','stem');

 set(gca,'XtickL',x_labels);
 set(h1,'FaceColor',my_Blue2(40,:),'EdgeColor',my_Blue2(40,:))
 set(h2,'Color',my_Orange(1,:),'LineWidth',0.5,'MarkerEdgeColor',my_Orange(1,:))

 set(pp(1),'Box','off')
 set(pp(2),'Box','off')

Update

I have managed to resolve the second issue with the x-axis labels. I simply added the line below. This sets the second x-axis labels to empty.

Still can't fix the first issue.

set(pp(2),'XTickLabel',[]);

Upvotes: 2

Views: 387

Answers (1)

am304
am304

Reputation: 13876

Try linkaxes:

linkaxes(pp,'y')

You may need to adjust the axes limits with pp(1).Ylim = ... to get the desired result.

Upvotes: 2

Related Questions