File Exchange

image thumbnail

borders

version 3.1.2 (6.88 MB) by Chad Greene
Simply plot national and US state boundaries, with or without Matlab's Mapping Toolbox.

79 Downloads

Updated 13 Jun 2019

View License

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.

Cite As

Chad Greene (2019). borders (https://www.mathworks.com/matlabcentral/fileexchange/50390-borders), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (54)

Looks like Moldova is missing

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

nice

Matthew

Thanks for your effort.

Thank you for the effort to make this excellent work.
Perhaps you might include continent border option such as 'europe' or 'asia'.

lvn

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

Hi Chad, I realy like your function but could you please add a patch for Europe.

Chad Greene

@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

hello chad..
any idea how plot pcolor (colored) above borders..
in my case borders lost my pcolor information
tks

roki khan

Tianqi Yu

masterpiece code,thanks a lot!

Chad Greene

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])

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

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])

Great function, Chad! Is there a way to make borders('countries','nomap') centered on the Pacific, though?

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:)

henyan deng

Sagar

John Ryan

GIOC

Hi Chad,
After I download this file, where should I put the files?
Thanks

Jan K. S.

Very simple to use! Here's a quick example:

borders('countries', 'Color', 'black')
hold on
borders('Brazil', 'FaceColor', 'green');

hads

Luís Silva

Hi,
Thank you for sharing.
How could I plot the boundary of the entire Europe?
Thanks,
Dong

Chad Greene

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')

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

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

Abhinav

Chad Greene

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

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

Thanks a lot for these functions. It saves a lot of time for me!!!!

AMMM

Is there anyway to put in a lat/lon area of interest? I'm trying to overlay borders on some gtopo30 data.

Chad Greene

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

Thanks for this! Any way to plot just the continental US without the state borders?

E. Cheynet

Chad Greene

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.

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?

Updates

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.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux