- Convert your gif image to true color, otherwise it will have to share the color map with the contours -- there is only one colormap per figure.
- By invoking image the way I did it'll place the pixels so that the wanted region is filled with the image. doc image if you want to know more
- chf = findobj(ch,'-property','FaceAlpha'); finds all the Children of your contour that have a 'FaceAlpha' property, which you then set to a value less than 1 to make them transparent: set(chf,'FaceAlpha',.3)
- Don't forget to hold on
Add world map background to contour plot
35 views (last 30 days)
I'm pretty new to MATLAB, & have the basic 2012b version with no toolboxes.
I have an outline map of the USA in .gif format (759x381 pixels), which I can display. I also have a contourf plot of temperature for the same latitudes/longitudes as the USA map, which I can also display.
I'd like to plot the contourf on top of the USA map, and have the colors of the contourf be semi-transparent so the map below can be seen.
The problem I'm running into is that I can't get them the same size. If I do the map first, the contourf just fills a tiny portion in the upper left of the figure. If I do the contourf first, only the very upper left portion of the map is plotted.
I found a function that makes the USA map gif smaller by scaling, however this causes an unacceptable loss of resolution. So, I'd like to know how to make the contourf plot bigger so it's the same dimensions as the USA map (759*381 pixels).
Thanks you for any help you can give!!
Jonathan Epperl on 10 Feb 2013
I hope you're still interested in an answer to this question, here's what I can offer:
lon = 30:2.5:150;
lat = 55:-2.5:-5; lat = lat';
[LO LA] = meshgrid(lon, lat);
da_grid = LO.^2.*LA;
cfig = figure('Position', [100, 100, 1400, 800]);
da_map = './new-york-county-map.gif';
[I,Imap] = imread(da_map);
% This converts your image with indexed colors to a true color image
Itc = ind2rgb(I,Imap);
% if you invoke image() like that it won't reverse axis direction etc.
ih = image('XData',lon([1 end]),'YData',lat([1 end]),'CData',Itc);
% Now the contours, save the handles the function supplies
[c,ch] = contourf(lon, lat, da_grid,10);
set(gca, 'Ytick', -5:5:55);
set(gca, 'xtick', 30:5:150);
colorbar; title('Wind Speed (m/s)');
chf = findobj(ch,'-property','FaceAlpha');
yl = ylabel('Latitude (degrees)');
xl = xlabel('Longitude (degrees)');
The crucial steps are really
If you have too many contours, then you will notice that the ones corresponding to the higher levels will seem more opaque. That is because unfortunately, contourf draws patches that overlap, the one for the highest level is just on top of everything else. If that's a problem we can think of solutions.
Lastly, I have the bug where all of a sudden, all labels are inverted, if you have that problem, see http://www.mathworks.com/matlabcentral/answers/30925
More Answers (3)
Kostas on 8 Feb 2013
If you had the Map toolbox, that would be quite easy to make it. Now i would suggest you to google for the M_Map: A mapping package for Matlab and see the examples there
t_123 on 4 Jun 2013
hey i have the same doubt ..i have to plot temp climatological data and to plot it in world map..i have converted both the images on jpg format..but dnt knw how to plot it together.pls help