matlab - Second x-axis label not fitting inside figure -


i trying add second x-axis figure. seems working, second axis label displayed half-outside of figure. is, see bottom half of "2nd axis" displayed. here small example demonstrate problem:

close all;  ax1 = gca; set(ax1,'xcolor','r','ycolor','r') xlabel(ax1, '1st axis');   data=rand(10,2); line(data(:,1), data(:,2), 'color', 'r');  ax2 = axes('position',get(ax1,'position'),...            'xaxislocation','top',...            'yaxislocation','right',...            'color','none',... % necessary, or axes not appear            'xcolor','k','ycolor','k'); xlabel(ax2, '2nd axis');  data=rand(10,2); line(data(:,1), data(:,2), 'color', 'k','parent', ax2); 

is there better way position axis label besides 'top'? or there way "fit inside figure"?

this command you:
'activepositionproperty','outerposition'
see this website additional information.
have adjust top axis, using command:

ax2 = axes('position',get(ax1,'position'),...        'xaxislocation','top',...        'yaxislocation','right',...        'color','none',... % necessary, or axes not appear        'xcolor','k','ycolor','k','activepositionproperty','outerposition'); 

if not important in order plot assembled, invert it, red axis fits other one:

close all;  ax2 = axes('xaxislocation','top',...            'yaxislocation','right',...            'xcolor','k','ycolor','k','activepositionproperty','outerposition'); xlabel(ax2, '2nd axis');  data=rand(10,2); line(data(:,1), data(:,2), 'color', 'k','parent', ax2);  ax1 = axes('position',get(ax2,'position'),...            'color','none',... % necessary, or not see second graph            'xcolor','r','ycolor','r'); xlabel(ax1, '1st axis');  data=rand(10,2); line(data(:,1), data(:,2), 'color', 'r'); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -