X-axis labelling problem when plotting 3different series's representation into 2different y axes
1 次查看(过去 30 天)
显示 更早的评论
I have a problem with the representation of 3 series in 2 y-axis and the corresponding x-axis labeling: * one with real values of a variable I called "effects". * one with real values of a variable I called "errors". * one with real values of a variable I called "cumulated effects". I would like to represent the two first series on a y-axis at left and the last one with the y-axis at right. I would like that all representations have a single x-axis labeling.
For this, * I started with the following variables values:
effects=[-0,0257;0,0241;-0,0230;-0,00945;0,00631];
errors=[0,0072;0,0092;0,0067;0,0058;0,0039];
cumulated effects=[0,290;0,562;0,822;0,929;1];
label=[{'RHa'} {'sc'} {'RHc * sc'} {'sa * sc'} {'sa'}];
- Then, I plotted "effects" in bar chart and errors in errorbars with, in both cases,"label" as x-label. Here is the code:
hold on
bar((1:size(effects,1)),effects,'b')
xlim([0.5 (size(effects,1)+0.5)]);
errorbar(effects,errors,'xr','LineWidth',2)
set(gca,'XTick',(1:1:size(effects,1)),'XTickLabel',label)
Up to this point, no problem. The problem starts when I try to plot the last serie. I then tried 2 options:
plot((1:size(effects,1)),cumulated effects);
Here, there is no labeling problem but I can't find a way to make the "cumulated effects" serie plotted to a new right y-axis.
plotyy((1:size(effects,1)),zeros(1,(1:size(effects,1))),... 1:size(effects,1)),cumulated effects);
In this case, the "cumulated effects" serie is correctly plotted on a right y-axis but a new x-labeling is superimposed on the x-axis: 1 2 3 4 5
I go through all the documentation for 2 days and I couldn't find the solution. Can you help me plotting the "cumulated effects" serie on right y-axis without this parasitic new x labeling ?
Thanks by advance and best regards.
0 个评论
采纳的回答
Sean de Wolski
2012-10-17
You can explicitly grab the handle to the new x-axis and set it's 'XTickLabel' to [].
ax = plotyy(etc);
set(ax,'XTickLabel',[]);
You may have to explicitly tell it which axes, i.e. ax(1) or ax(2), however I can't run your code to reproduce the issue.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!