Matlab does not allow to combine use more than one colormap in a figure. However there are some possibilities to get around this problem, which are presented in this article.
Initialization and export of figure
For all plots the same initialization for the data and the figure is used:
% clear command window, figures and all variables clc; clf; clear all; %% Common variables FontSize = 12; FontName = 'MyriadPro-Regular'; % or choose any other font doExportPlot = true; %% Plot variables SaveDir = ''; TITLE = ''; xLabelText = 'x-values'; yLabelText = 'y-values'; zLabelText = 'function values'; %% SaveDir = ''; BaseDir = ''; %% Create Data [x y data] = peaks(1000); data = data - min(min(<span class="hiddenGrammarError" pre="">data)); data</span> = data / max(max(data)); %% start plot % figure dimensions in cm. I choose 1.5 or 2 times % the target size typically. If figure is display in % document much smaller increase the fontsize. figure_width = 14; figure_height = 10; % --- setup plot windows figuresVisible = 'on'; % 'off' for non displayed plots (will still be exported) hfig = figure(1); clf; set(hfig,'Visible', figuresVisible) set(hfig, 'units', 'centimeters', 'pos', [5 5 figure_width figure_height]) set(hfig, 'PaperPositionMode', 'auto'); set(hfig, 'Renderer','zbuffer'); set(hfig, 'Color', [1 1 1]); % Sets figure background set(gca, 'Color', [1 1 1]); % Sets axes background % --- dimensions and position of plot hsp = subplot(1,1,1, 'Parent', hfig); set(hsp,'Position',[0.12 0.15 0.80 0.8]); colorDepth = 1000; |
And the same code is used to style the plot and export the figure:
%% setup axis plot properties % shading interp; % interpolate pixels axis on; % display axis axis tight; % no white borders set(gca, ... 'Box' , 'on' , ... 'TickDir' , 'in' , ... 'TickLength' , [.02 .02] , ... 'XMinorTick' , 'off' , ... 'YMinorTick' , 'off' , ... 'XGrid' , 'off' , ... 'YGrid' , 'off' , ... 'XColor' , [.0 .0 .0], ... 'YColor' , [.0 .0 .0], ... 'LineWidth' , 0.6 ); %% axis scales % set(gca,'XTick',-15:5:15) % set(gca,'YTick',-10:5:10) %% label texts % save handles to set up label properties hTitle = title(TITLE); hXLabel = xlabel(xLabelText); hYLabel = ylabel(yLabelText); %% set properties for all handles set([gca, hTitle, hXLabel, hYLabel], ... 'FontSize' , FontSize , ... 'FontName' , FontName); %% last 'bug' fixes % bring axis on top again (fix matlab bug) set(gca,'Layer', 'top'); %% export drawnow doExportPlot = true; if (doExportPlot) IMAGENAME = [SaveDir SaveName]; print(hfig, ['-r' num2str(400)], [IMAGENAME '.png' ], ['-d' 'png']); end |