about plotting two images in pseudocolor figures
-
17-06-2021 - |
Question
I am using matlab to visualize my data in pseudocolor figures (pcolor
). It works pretty good to show the data in pcolor but now I get one more data set. If I plot each data set in a separate pcolor plot, everything is fine. But now, I combine the two data such that
NEW_DATA = [OLDDATA1, OLDATA2]
if I pcolor the NEW_DATA instead, the color get messed up. Is that any way I can show the combined data without losing any detail or color information. In my case, if you plot pcolor(NEW_DATA)
, the general shape was maintained (just like [pcolor(OLDDATA1), pcolor(OLDATA2)]
) but some detail become fuzzy
Solution
In pcolor plots, the vertex colors are scaled into the color map. You can set the scaling using the 'clim'
property of the axes. I'm guessing what is happening here is that the scaling is different between the two OLDDATA
and the combined NEWDATA
.
Ultimately you need to decide which scaling to use; if you like the original from OLDDATA1
, you could do the following:
pcolor(OLDDATA1);
orig_clim = get(gca,'clim'); %# just to get the color limits
pcolor(NEWDATA);
set(gca, 'clim', orig_clim);
If you like the original scaling of both OLDDATA
plots and there isn't a scaling that works for both, you can manually create a figure with two axes placed adjacent to each other (rather than relying on subplot
). Each axes object can have its own clim
that way, but the two plots will appear contiguous.
figure;
h1 = axes('units','normalized','position',[.05 .05 .45 .45]);
h2 = axes('units','normalized','position',[.5 .05 .45 .45]);
pcolor(h1, OLDDATA1);
pcolor(h2, OLDDATA2);
set(h2, 'ytick', []); %# turn off ytick (if it was on)