about plotting two images in pseudocolor figures - matlab

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

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)

Related

Removing the edge line on a contour plot

I used Matlab to create a polar coordinate and converted it into Cartesian coordinate.
[th,r] = meshgrid((0:0.5:360)*pi/180,0:.02:1);
[X,Y] = pol2cart(th,r);
I get data on this mesh and produce a contourf plot over it.
My problem is that I get a center line in my contourf plot which I would like to remove, could some help me with this
Thank you
If I extend a little bit your example to get something I can plot, I do reproduce the problem:
[th,r] = meshgrid((0:0.5:360)*pi/180,0:.02:1);
[X,Y] = pol2cart(th,r);
Z = sqrt( X.^2 + Y.^2 ) ;
isoLevel = 0:0.1:10 ;
[C ,hc] = contourf(X,Y,Z,isoLevel) ;
The black line at the interface is because the function contourf create patch objects and these objects tend to "close" themselves (they will create a line between the first and last point defined in their profile).
This is easier to observe if you do not complete the definition of your profile over 360 degrees. The picture on the right shows you the same example but with the grid only from 0:350 and with the LineStyle set to :.
As you can see, it is difficult to control how Matlab will actually render this specific profile limit. There are ways to control specific edges of patch objects but in this case it would involve retrieving the handle of each patch object (10 in my case but many more in more complex cases), locating the edge you want to control and basically redefining the patch (each of them). You'd be better off drawing the patches from scratch yourself.
Fortunately, there is a simple ways out of that: Get rid of all the patch edge lines...
but then you may miss your isolines! No problem, just plot them on top of the patches !
You get all your colored patches (with no border) and a set of (iso)lines over which you have full control.
Two easy way to get you patch without lines (i) set the shading to shading flat, or (ii) specify 'EdgeColor','none' in the parameter of the contourf function.
To get your isolines on top, use the sister contour function.
So using the same X,Y and Z data than previously:
isoLevel = 0:0.1:10 ;
[C ,hc] = contourf(X,Y,Z,isoLevel,'EdgeColor','none') ; %// set of patches without border
% shading flat %// use that if you didn't specify ('EdgeColor','none') above
hold on
[C2 ,hc2] = contour(X,Y,Z,isoLevel,'LineColor','k') ; %// now get your isolines
will render:
It's a good idea to store the handle hc2 in case you want to modify your isolines properties (color, style, thicknes etc ...).
Also, specifying the isoline levels is recommended. This way you can make sure both contour and contourf will use the same set of isovalues. It could probably work without this (because the underlying dataset is the same), but personally I always prefer to be explicit and not rely on background calculations.

Determining the region with data in a pcolor plot

I have a plot showing a map in a pcolor plot in Matlab R2012a/R2014a (=using the old graphic system) and want to implement panning and zooming.
Because the dataset is quite large (and needs to be interpolated from vector data), I would prefer not to plot the whole region at high resolution, but only a small fraction of it and then pan around. But I want to redo the plot once I pan out of this subregion, such that it contains the next subregion.
Is there some way to get the limits of the region with data in an axes object the same way I can the limits of the currently displayed region via get(myAxes, '[XY]lim')? This way I could replot only if necessary.
A workaround would be to store the limits inside a handles structure everytime I execute pcolor, but I wonder if there is something built ín for this case.
I found a solution.
The region is not stored in the axes object itself, but in one of its children (the one containing the actual plot). It is if type surface for pcolor plots and hggroup for contour plots. So you can find it via
childHandle = plotfindall(myAxes, 'Type', 'surface')
This object contains all the data used for plotting in its properties XData, YData and ZData. The largest x value with data and already plotted (but maybe not in the visible range) can be determined via
xd = get(childHandle, 'XData');
maximumXWithData = max(xd(:));

plotting a text file with 4 columns in matlab

I want to plot a text file with 4 columns that first column in longitude,second in latitude, third is depth and forth is amount of displacement in each point.(it's related to a fualt)
-114.903874 41.207504 1.446784 2.323745
I want a plot to show the amount of displacement in each point (like images that we plot with imagesc),unfortunately "imagesc" command doesn't work for it.
how can I plot it?
Thanks for your attention
A simple way would be to use scatter3 and assign your displacements to be the colours. Note that you have to supply a size for this to work - I'm using [] (empty matrix) which will set it to default. If your four sets of values are four vectors of the same size, then it's just something like:
scatter3(lat,lon,depth,[],displacement, 'filled')
Values in displacement will be linearly mapped to the current colormap. 'filled' gives you filled markers rather than open ones (default marker is a circle but can be changed).
You can plot each point using plot3(longitude,latitude,depth). You can color each point according to the displacement in a for loop. The easiest way to do this is create a colormap, e.g. using jet and chosing the color according to the displacement.
figure;
hold on;
cmap = jet(256);
dispRange = [min(displacement),max(displacement)];
for k=1:size(longitude,2)
c = cmap(1+round(size(cmap,1)*(displacement(k)-dispRange(1))/dispRange(2)),:);
plot3(longitude(k),latitude(k),depth(k),'o', ...
'MarkerEdgeColor',c,'MarkerFaceColor',c);
end

putting together 2 contours in matlab.

I'm making my own Shakemap (so far, Shamemap) with Matlab. A Shakemap is a representation of the intensity of ground shaking in a map (google it up for more info). I want it to be similar to those from the USGS, in which they plot the intensity using a jet colormap and they control the shading to represent the altimetry data. So far I haven't figured out how they do this.
I have a set of coordinates with the location's elevation (from NASA's SRTM) and in the same set of coordinates I have some parameters of ground shaking.
[lat long SRTM]
[lat long GroundShaking]
I can contour them separately, but if I put them in the same figure just like that one overrides the other.
How can I put them in the same figure? I have thought about assigning a new value to each location such that the new value accounts for both measures; locations with the same GroundShaking parameter should be the same color, but if one is higher then that one should be darker. Unfortunately I don't know how to implement this. I have also thought about setting the alpha feature manualy, but I can't make it work only for the Ground Shaking data. Any suggestions ?
MWE:
x=0:0.01:1;
y=0:0.01:1;
[xx,yy]=meshgrid(x,y);
asd1=zeros(length(x),length(y));
ads2=asd1;
for i=1:length(x)
for j=1:length(y)
asd1(i,j)=x(i)*y(j);
asd2(i,j)=x(i)*x(i)+y(j)*y(j);
end
end
c1=griddata(x,y,asd1,xx,yy, 'linear');
c2=griddata(x,y,asd2,xx,yy, 'linear');
contourf(asd1)
contourf(asd2)
alpha(0.5)
(MWE unrelated to the map because the data is huge)
You need to add a hold on so that the first plot is not overwritten. This nearly works.
colormap gray
map1=colormap
colormap jet
map2=colormap
M=[map1;map2];
asd2=asd2*(max(asd1(:))-min(asd1(:)))/(max(asd2(:))-min(asd2(:)));
asd2=asd2-max(asd2(:));
colormap(M)
caxis([min(asd2(:)) max(asd1(:))])
figure(1)
contourf(asd1)
figure(2)
contourf(asd2)

Matlab - plot two pcolors on top of each other, with different colormaps

I'm plotting two pcolors on top of each other (using the m_map algorithm m_pcolor). The reason for this is that the second pcolor has transparency in it, and so shows the pcolor underneath. The first plot consists of just ones and zeroes, and I would like it to be just black and white. I would like the second to use the colormap jet, but I can't work out how to set one colormap without changing the other. My code at the moment is:
h1 = m_pcolor(Lon', Lat', black_background);
hold on;
h = m_pcolor(Lon', Lat', input_matrix);
Thanks in advance,
Adam
For this limited application, the easiest way is probably to append a row of zeros onto the colormap, deal with scaling (the clim property) yourself so that each plot takes advantage of the appropriate part of the colormap.
cm=colormap('jet'); %# Nx3
cm = [cm; 0 0 0]; %# append black row: (N+1)x3
h1 = m_pcolor(Lon',Lat',black_background);
set(h1,'clim',[length(colormap),length(colormap)])
hold on
h2 = m_pcolor(Lon', Lat', input_matrix);
set(h2,'clim',[length(colormap)-1, length(colormap)-1])
This should get you close, but I haven't tested it since I'm not on my matlab machine.
Another option is freezeColors from the file exchange (but this may only work for different axes within the same figure window, I'm not sure about different plots in the same axes object).