I am trying to bring two pcolor plots on top of each other with different colormaps. One of the colorbars goes out of the figure window, have tried placing the colorbar in other places like southoutside or westoutside and the same problem persists. Is there any better way to do it? Any help is appreciated.
f = figure; ax = gca; ax(2) = copyobj(ax, ax.Parent); linkprop([ax(1), ax(2)], {'XLim', 'YLim','Position', 'View'}); p = pcolor(ax(1), xc, yc, e); set(p, 'EdgeColor', 'none', 'FaceAlpha', 1); set(ax(1), 'Colormap', bone); cb(1) = colorbar(ax(1), 'eastoutside'); p2 = pcolor(ax(2), xc, yc, d); set(p2, 'EdgeColor', 'none', 'FaceAlpha', 0.5); set(ax(2), 'Colormap', copper); cb(2) = colorbar(ax(2), 'northoutside'); ax(2).Visible = 'off'; ax(1).XAxis.FontSize = 14; ax(1).YAxis.FontSize = 14; ax(2).XAxis.FontSize = 14; ax(2).YAxis.FontSize = 14; ax(1).FontSize = 14; ax(2).FontSize = 14; xlabel('x(\mum)'); ylabel('y(\mum)'); %exportgraphics(gcf, 'trial.png', 'Resolution', 300);
The issue you are running into is due to this line of code:
linkprop([ax(1), ax(2)], {'XLim', 'YLim','Position', 'View'});
That line of code is setting the Position property on the axes, which switches the PositionConstraint from 'outerposition' to 'innerposition'.
f = figure; t = tiledlayout(1,1); ax(1) = axes(t); p = pcolor(ax(1), peaks); set(p, 'EdgeColor', 'none', 'FaceAlpha', 1); set(ax(1), 'Colormap', bone); cb(1) = colorbar(ax(1)); cb(1).Layout.Tile = 'east'; ax(2) = axes(t); p2 = pcolor(ax(2), peaks); set(p2, 'EdgeColor', 'none', 'FaceAlpha', 0.5); set(ax(2), 'Colormap', copper); cb(2) = colorbar(ax(2)); cb(2).Layout.Tile = 'north'; ax(2).Visible = 'off'; ax(1).XAxis.FontSize = 14; ax(1).YAxis.FontSize = 14; ax(2).XAxis.FontSize = 14; ax(2).YAxis.FontSize = 14; ax(1).FontSize = 14; ax(2).FontSize = 14; xlabel(ax(1),'x(\mum)'); ylabel(ax(1),'y(\mum)');
Note: When you call linkprop, you have to store the output handle, otherwise the link will be broken immediately. The output from linkprop is a link object that "owns" the link. If you don't store that object, then the link object will be stored in ans, but that will be cleared as soon as the next command runs. Once that link object is cleared, the link will be broken.
link = linkprop([ax(1), ax(2)], {'XLim', 'YLim','View'});
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.