Discussion:
contour overlaying pcolor
(too old to reply)
Colm
2009-04-24 11:29:02 UTC
Permalink
Hi,

I'm trying to overlay a contour plot of bathmetry over a pcolor plot, but when I plot the contour plot, it turns the whole pcolor plot a nasty shade of brown. I assume it's to do with the color commands of the contour plot messing with the colours of the pcolor, but is there anyway of stopping this happening?

I'm using a Lambert projection, if that makes any difference.
Francis Burton
2009-04-26 17:09:47 UTC
Permalink
Post by Colm
I'm trying to overlay a contour plot of bathmetry over a pcolor plot,
but when I plot the contour plot, it turns the whole pcolor plot a nasty
shade of brown. I assume it's to do with the color commands of the
contour plot messing with the colours of the pcolor, but is there anyway
of stopping this happening?
Are you overplotting with a filled contour plot and then setting
its transparency (alpha), or just contour lines?

Francis
Colm
2009-04-27 09:38:01 UTC
Permalink
Post by Francis Burton
Post by Colm
I'm trying to overlay a contour plot of bathmetry over a pcolor plot,
but when I plot the contour plot, it turns the whole pcolor plot a nasty
shade of brown. I assume it's to do with the color commands of the
contour plot messing with the colours of the pcolor, but is there anyway
of stopping this happening?
Are you overplotting with a filled contour plot and then setting
its transparency (alpha), or just contour lines?
Francis
It's just contour lines. I'm using m_map to plot the lambert projections, not sure if that has anything to do with it.
Francis Burton
2009-04-27 14:50:49 UTC
Permalink
Post by Colm
Post by Francis Burton
Post by Colm
I'm trying to overlay a contour plot of bathmetry over a pcolor plot,
but when I plot the contour plot, it turns the whole pcolor plot a nasty
shade of brown. I assume it's to do with the color commands of the
contour plot messing with the colours of the pcolor, but is there anyway
of stopping this happening?
Are you overplotting with a filled contour plot and then setting
its transparency (alpha), or just contour lines?
It's just contour lines. I'm using m_map to plot the lambert
projections, not sure if that has anything to do with it.
It may be m_map - I have never used it myself.

Are you using m_pcolor and m_contour, or MATLAB native functions?

Francis
Colm
2009-04-28 10:28:01 UTC
Permalink
Post by Francis Burton
Post by Colm
Post by Francis Burton
Post by Colm
I'm trying to overlay a contour plot of bathmetry over a pcolor plot,
but when I plot the contour plot, it turns the whole pcolor plot a nasty
shade of brown. I assume it's to do with the color commands of the
contour plot messing with the colours of the pcolor, but is there anyway
of stopping this happening?
Are you overplotting with a filled contour plot and then setting
its transparency (alpha), or just contour lines?
It's just contour lines. I'm using m_map to plot the lambert
projections, not sure if that has anything to do with it.
It may be m_map - I have never used it myself.
Are you using m_pcolor and m_contour, or MATLAB native functions?
Francis
I'm using the m_ functions (m-contour, etc).

I've tried using the lower level m_elev as well but it's the same problem. Is there a way of plotting two separate figures and overlaying them on each other after the fact? The axes/projections would be the same so it should be possible? If I lower the background transparency on the contour plot, it might work?
Francis Burton
2009-04-28 18:52:25 UTC
Permalink
Post by Colm
I'm using the m_ functions (m-contour, etc).
That's what I thought. I am completely in the dark about this
3rd party library, so I doubt my fumblings would be much use to
you. Have you tried contacting the author(s) of the package?
If what you are attempting is reasonable, there's a good chance
they would be willing to help sort out your problem. Good luck!

Francis
Colm
2009-05-07 08:41:02 UTC
Permalink
Post by Colm
Hi,
I'm trying to overlay a contour plot of bathmetry over a pcolor plot, but when I plot the contour plot, it turns the whole pcolor plot a nasty shade of brown. I assume it's to do with the color commands of the contour plot messing with the colours of the pcolor, but is there anyway of stopping this happening?
I'm using a Lambert projection, if that makes any difference.
Anyone else have any ideas?
Marcelo Castro
2009-05-28 18:05:03 UTC
Permalink
Post by Colm
Post by Colm
Hi,
I'm trying to overlay a contour plot of bathmetry over a pcolor plot, but when I plot the contour plot, it turns the whole pcolor plot a nasty shade of brown. I assume it's to do with the color commands of the contour plot messing with the colours of the pcolor, but is there anyway of stopping this happening?
I'm using a Lambert projection, if that makes any difference.
Anyone else have any ideas?
Hi,

I'm having a similar problem, but I?m trying to use pcolor over a contour plot (to plot a concentration map over a bathymetry contour). When I put the pcolor plot the contour changes to the highest associated color of the colormap in the pcolor plot.
I think it has something to do with the colormap associated with the figure. Is it possible to use two different colormaps in one figure? If it is, problem solved...
1) As I couldn't use two colormaps in one figure, I edited a jet colormap so that the "pcolor highest value associated color +1" was black.
2) Then I created a NaN matrix the same size of the matrix used on the pcolor plot and transformed, only the cells associated with the exterior contour plot, to the value associated with the black color on the colormap.
3) Then I added the two (the original pcolor matrix and the one I created), so my new matrix had the pcolor values and they were surounded by the values associated with the black color on the colormap.
4) And then plot (pcolor) the new matrix. It should work.
5) Then, if you want to plot the colorbar as well, you?ll have to limit the scale of this colorbar to the (black color value -1), or the highest value of the original pcolor plot, so that the black color doesn?t appear on your colorbar.

As I have to process maybe a thousand maps i'm trying to make a script to generate them all, but as i?m using many different variables (such as BOD and total phosphorous), I have to change the scale of the colormap constantly, and this is causing trouble.

But, with the method above I was able to plot one figure that was really good. So this should be a start.
Hope this helps
Sarah
2009-07-03 16:40:02 UTC
Permalink
Wow. That seems really complicated.
After much trial and error I've found a straightforward way to make this work. You just need to redefine caxis at the end.

% First make the pcolor plot:
hSurf=pcolor(X, -Y, Z); % This is the command to make a shaded contour plot
shading interp;
hSurfAx=(gca);
cRange= caxis; % get the default color map for the data range

% do other cosmetic stuff here, titles, axes, select colors (colormap(hSurfAx, 'summer')), etc, etc.

% Then add contour lines with appropriate Z data (I am overlaying temperature on other parameters):
[C hT]= contour( X, -Y, Z2, num_lines, '-k');
hLines=findobj(gca, 'type', 'line'); % find all the separate lines on contour plot.
set(hLines, 'LineWidth', 1); % and set their width.

% Then reset the color axis according to the range determined above:
caxis(cRange);
Ines
2010-12-10 10:28:04 UTC
Permalink
Dear Sarah,

I had the same problem a previous user had (overlying bathymetry contour on pcolor) when using the m_map toolbox.
I tried your solution, and it worked perfectly.
Thanks for posting.

My best wishes,
Inès
Luis
2012-04-03 22:05:18 UTC
Permalink
Post by Ines
Dear Sarah,
I had the same problem a previous user had (overlying bathymetry contour on pcolor) when using the m_map toolbox.
I tried your solution, and it worked perfectly.
Thanks for posting.
My best wishes,
Inès
I had a very similar problem using standard Matlab functions. I just added the following line

caxis(caxis)

after the first contour plot.

Best,
Luis
Qiu
2016-06-12 21:46:03 UTC
Permalink
Post by Luis
Post by Ines
Dear Sarah,
I had the same problem a previous user had (overlying bathymetry contour on pcolor) when using the m_map toolbox.
I tried your solution, and it worked perfectly.
Thanks for posting.
My best wishes,
Inès
I had a very similar problem using standard Matlab functions. I just added the following line
caxis(caxis)
after the first contour plot.
Best,
Luis
wow, that works. caxis(caxis) seems to fix the caxis as the pcolor figure. Thanks.
Larry Gulliver
2022-04-19 17:32:41 UTC
Permalink
Thank you, Sarah. This worked. I used this for plotting a tracking formula (MOW) of 0.5 over potential vorticity (qq) and it came out brilliant. I posted the code below even though many of the variables may not make sense.
figure(1)
mt= 0.5;
pcolor(x,y,qq(:,:,1)');shading interp; colorbar
colormap(jet(256));
set(gca,'ydir','norm')
daspect([1 1 1])
cRange=caxis;
drawnow
hold on
[c,H]=contour(x,y,MOW(:,:,1)',[mt mt],'k');
hlines=findobj(gca,'type','line'); % finds all the lines on the colorplot
set(hlines,'LineWidth',1);
caxis(cRange);
end
hold off

Loading...