Matlab bar plot grouped but in different y scales

前端 未结 1 661
你的背包
你的背包 2021-01-03 07:19

I have two sets of data, and I want to plot using bar graph. But the problem is these two sets of data are at quite different scale. If I just use the bar(A), i

相关标签:
1条回答
  • 2021-01-03 07:42

    This uses the plotyy(x1,y1,x2,y2,fun1,fun2) variant of plotyy:

    %// Set these three variables as desired
    offset = (x(2)-x(1))/8;
    width = (x(2)-x(1))/4;
    colors = {'b','g'};
    
    %// Do the plot
    plotyy(x-offset,y1,x+offset,y2, @(x,y) bar(x,y,width,colors{1}), @(x,y) bar(x,y,width,colors{2}));
    

    enter image description here

    If you prefer x-ticks to appear only on used x values:

    h = plotyy(x-offset,y1,x+offset,y2, @(x,y) bar(x,y,width,colors{1}), @(x,y) bar(x,y,width,colors{2}));
    set(h,'xtick',x)
    
    0 讨论(0)
提交回复
热议问题