This submission contains functions to plot the outlines and names of National borders and US states. Matlab's Mapping Toolbox is NOT required.
There are two functions for plotting: borders and bordersm, and they both work the same way, except that bordersm is for use with maps created using Matlab's Mapping Toolbox. Similarly, labelborders and labelbordersm place text labels within the boundaries of countries or states.
Chad Greene (2019). borders (https://www.mathworks.com/matlabcentral/fileexchange/50390-borders), MATLAB Central File Exchange. Retrieved .
3.1.2 | Updated live scripts |
|
3.1.1 | Added live scripts |
|
3.1 | Fixed a bug in bordersm, which previously resulted in an error when plotting multiple countries as patch objects. |
|
3.0 | Separated borders into two functions: Now, bordersm is the function to use with Matlab's Mapping Toolbox. |
|
1.1.0.0 | Now allows plotting national or state outlines as patch objects with or without the Mapping Toolbox. |
Inspired by: WORLDDATAMAP, Google Earth Toolbox, zoharby/plot_google_map, land_or_ocean.m, landmask, strlookup
Inspired: EOF, patchsc, scattertextm, Arctic Sea Ice
Create scripts with code, output, and formatted text in a single executable document.
Jonathan Wolf (view profile)
Excellent. And extremely easy to edit. 6 stars. Nothing more to say.
khaoula karroum (view profile)
Denis Anikiev (view profile)
Looks like Moldova is missing
Pavel Inchin (view profile)
Good day. I have a problem with using this script, so my code:
figure
borders('Japan','color','k','linewidth',2);
axis tight
I have an error:
Error using matlab.graphics.axis.Axes/set
Children may only be set to a permutation of
itself
Error in
map.graphics.internal.restackMapAxes>moveToTop
(line 85)
set(ax,'Children',[h(:); c])
Error in map.graphics.internal.restackMapAxes
(line 72)
moveToTop(ax, hUserText)
Error in linem (line 115)
map.graphics.internal.restackMapAxes(h0)
Error in plotm (line 61)
hndl0 = linem(lat,lon,varargin{:});
Error in borders (line 197)
h = plotm(lat,lon,varargin{:});
sara abdali (view profile)
nice
Matthew (view profile)
Thanks for your effort.
niccolo dematteis (view profile)
Thank you for the effort to make this excellent work.
Perhaps you might include continent border option such as 'europe' or 'asia'.
Sourangsu Chowdhury (view profile)
lvn (view profile)
Would be great if you could also include the Chinese provinces, analogous to the US states. Note that
https://nl.mathworks.com/matlabcentral/fileexchange/29462-china-province-mat
is not fully compatible as the country borders of China are slightly different.
lvn (view profile)
Ehsan Modiri (view profile)
Vinit Sehgal (view profile)
Martin Fuchs (view profile)
Hi Chad, I realy like your function but could you please add a patch for Europe.
Chad Greene (view profile)
@eko: Make sure you use the *hold on* command to make sure the pcolor information isn't lost. If the issue is that borders cover up your pcolor plot, call borders first. Or do something like
h = pcolor(lon,lat,z);
shading flat
hold on
borders
uistack(h,'top') % brings pcolor to the top
eko supriyadi (view profile)
hello chad..
any idea how plot pcolor (colored) above borders..
in my case borders lost my pcolor information
tks
roki khan (view profile)
Tianqi Yu (view profile)
masterpiece code,thanks a lot!
Chad Greene (view profile)
Hi Sébastien,
I think you want to specify 'EdgeColor' instead of 'Color' if you're plotting as patches. That would look like this:
borders('countries', 'edgeColor', [1 0 0],'facecolor', [0 1 0])
Sébastien MAILFERT (view profile)
Dear Chad,
You did a really interesting work and I'm using it regularly.
I'm not able to draw the all the country borders in one color and fill them with another color.
I'm trying to do Something like this:
borders('countries', 'Color', [1 0 0],'facecolor', [0 1 0])
but it does not work.
Could you help me please?
Best
Sébastien
Chad Greene (view profile)
Hi Dillon,
Good question! This solution's a little bit clunky, but it works. The idea is plot the borders twice, and move the second set over by 360 degrees longitude. Then set the axis limits however you'd like.
h1 = borders('countries','nomap');
h2 = borders('countries','nomap');
for k = 1:length(h2)
h2(k).XData = h2(k).XData + 360;
end
axis([0 360 -90 90])
Dillon Amaya (view profile)
Great function, Chad! Is there a way to make borders('countries','nomap') centered on the Pacific, though?
Catubela matlab (view profile)
Hi Chad, This is such a great function!
Thanks for taking the time to provide it.
Can you tell me, do you know if it's possible to add countries to the list that are not included? Like Moldova or Macedonia?
Many thanks in advance:)
Vipul Panwar (view profile)
Vadim Poskakukhin (view profile)
henyan deng (view profile)
Sagar (view profile)
John Ryan (view profile)
GIOC (view profile)
Fernando Ferreira (view profile)
Yuecheng Zhao (view profile)
Hi Chad,
After I download this file, where should I put the files?
Thanks
Jan K. S. (view profile)
Very simple to use! Here's a quick example:
borders('countries', 'Color', 'black')
hold on
borders('Brazil', 'FaceColor', 'green');
Farhad Sedaghati (view profile)
hads (view profile)
Luís Silva (view profile)
Jianzhi Dong (view profile)
Hi,
Thank you for sharing.
How could I plot the boundary of the entire Europe?
Thanks,
Dong
Casper Volger (view profile)
Chad Greene (view profile)
Hi Casper,
I must have missed WobRotsons question. I will try to answer it and your question here. If you're using Matlab's Mapping Toolbox, set the axis limits with worldmap before plotting borders. Like this:
worldmap([-6 2],[-82 -74])
borders
Then add the lat,lon locations of platforms by
plotm(lat,lon,'o')
If you are not using Matlab's Mapping Toolbox, you can plot lons and lats just like they are x and y values. That would look like this:
axis([-82 -74 -6 2])
borders
plot(lon,lat,'bo')
If you're not using Matlab's Mapping Toolbox, you can always plot in "unprojected" coordinates, where you just treat longitudes like x values and latitudes like y values. If you don't mind some spatial distortion, that's probably okay.
Another option for your particular case is to use my arcticborders function, which plots in polar stereographic coordinates. Get it here: https://www.mathworks.com/matlabcentral/fileexchange/56923. Then to plot your platform locations use polarstereo_fwd (also on File Exchange) to transform your lat,lon locations to projected x,y coordinates, something like
[x,y] = polarstereo_fwd(lat,lon);
plot(x,y,'bo')
Casper Volger (view profile)
Hi Chad,
I am using your function for my school project on the North Sea, my first question is kind of the same as WobRotsen. Is it possible to plot a certain lat-lon box. My second question is of it is possible to plot certain coordinates (location of offshore platforms) in the map?
Thanks in advance!
WobRotson (view profile)
is there a way to only plot within a certain lat-lon box? trying to plot up a map of Ecuador-Colombia-Peru borders within a -82:-74 lon -6:2 lat box. tried extracting the lat-lon data for each border as per doc file and then slecting only the relevant points but it leaves lines joining points from corners...
Kevin Quinn (view profile)
Abhinav (view profile)
Chad Greene (view profile)
Hi Marina,
For a list of countries type
load borderdata.mat
sort(places)
Latin America is not one of the options, so you'll have to plot each country in Latin America individually. Alternatively, you could add this to the input parsing section:
if strncmpi(place,'latin america',4)
plotWhat = 'latin america';
end
and add this under "switch plotWhat"
case 'latin america'
lat = bd.lat([8 17 21 33 38 39 41 48 49 55 75 78 79 120 159 165 162 211 214]);
lon = bd.lon([8 17 21 33 38 39 41 48 49 55 75 78 79 120 159 165 162 211 214]);
although I can't guarantee the results. Good luck!
Marina (view profile)
Is there a list with countries included in the borders pack?
I'd love to map Latin America, but it doesn't seem to be included...Thanks
Long Cheng (view profile)
Md Atiqul Islam (view profile)
Thanks a lot for these functions. It saves a lot of time for me!!!!
AMMM (view profile)
Is there anyway to put in a lat/lon area of interest? I'm trying to overlay borders on some gtopo30 data.
Barnaby Dobson (view profile)
Maxime Hervo (view profile)
Chad Greene (view profile)
Jinny, It's not a wonderful solution but this works:
bd = load('borderdata.mat');
plot(bd.lon{209}(2684:9140), bd.lat{209}(2684:9140))
Jinny Lee (view profile)
Thanks for this! Any way to plot just the continental US without the state borders?
E. Cheynet (view profile)
Chad Greene (view profile)
Behnam, thanks for the note. The border outlines here are from the US Census Bureau 500k dataset. If you need higher resolution you might have to search the internet for France-specific outlines.
Behnam Zakeri (view profile)
Thanks a lot for the input. The borders for France seems to have a bit mismatch in north-east parts. Could you please check it again?
teste testarei (view profile)
Kaustubh Thirumalai (view profile)