File Exchange

image thumbnail


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


Updated 20 Feb 2020

View Version History

View License

* * * The functions on this page are no longer being updated. They should still work as shown in the examples here, but I am only actively maintaining the versions of these functions which are in the Climate Data Toolbox for MATLAB, which can be found here * * *

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

Greene, Chad A., et al. “The Climate Data Toolbox for MATLAB.” Geochemistry, Geophysics, Geosystems, American Geophysical Union (AGU), July 2019, doi:10.1029/2019gc008392.

View more styles

Comments and Ratings (71)

Chad Greene

@A: Good question! The easiest solution I can think of is to create an extra set of axes, something like this:

borders('continental us')
axis off
pos = get(gca,'pos');
axes('position',[pos(1) pos(2) 0.2 0.2])
axis([-180 -129 51 72])
axis off


Thanks for this file. It's really helpful, and easy to use. Is there a way to tighten up the map, so that Alaska and Hawaii aren't so far away? It ends up distorting the map when they are added.


Spencer Thomas

found Loas - was my fault for missing Lao People's Democratic Republic in the (extrermly) useful did you mean list that it outputs when it can find the name.
cant edit my previous comment so just adding another one.
Excellent work Chad!

Spencer Thomas

This is a great function and easy to use. The examples are very clear. Easy to install
For some reason Laos is not included in the list of countries and the only one you can colour in. I've looked at borderdata.mat and there's nothing I can see - might be an issue outside this toolbox though.

Spencer Thomas

gao yang

Taiwan belongs to China!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Taiwan belongs to China!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Taiwan belongs to China!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Taiwan belongs to China!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Taiwan belongs to China!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Taiwan belongs to China!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Teja Dasari

Very nice function! How to use this function inside UI axes?

Chad Greene

@Abdul: The borderdata.mat file is included in the zip file.

Abdul Kadir Alhamid

Where can I found the borderdata.mat?


Thank you so much chad ! Works perfectly now :)

Chad Greene

Hmm, sorry about that Jacques. Maybe try deleting this block:

if license('test','map_toolbox')


Hi, whether I use borders or bordersm I always get the same error :

"To use 'ismap', the following product must be both licensed and installed:
Mapping Toolbox"

I don't understand why.. Any help please ??



Chad Greene

@Chad Small: Oh yes, I see the issue. This standalone version of the function is old, but you found the documentation for a newer version which is in the Climate Data Toolbox. I'll try to update this standalone version soon, but in the meantime you can get CDT here and that should work.

Chad Small

Hi Chad,

This is an excellent tool. My only issue is that when I try to run the code to change my central longitude:

It gives me back this error:
Error using plot
There is no center property on the Line class.

Error in borders (line 161)
h = plot(cell2nancat(lon),cell2nancat(lat),varargin{:});

Do you have any thoughts on why this might be, or is there another way to change my central longitude?


Leonardo Colavitti

Very nice tool!

Jonathan Wolf

Excellent. And extremely easy to edit. 6 stars. Nothing more to say.

khaoula karroum

Denis Anikiev

Looks like Moldova is missing

Pavel Inchin

Good day. I have a problem with using this script, so my code:
axis tight

I have an error:
Error using
Children may only be set to a permutation of

Error in>moveToTop
(line 85)
set(ax,'Children',[h(:); c])

Error in
(line 72)
moveToTop(ax, hUserText)

Error in linem (line 115)

Error in plotm (line 61)
hndl0 = linem(lat,lon,varargin{:});

Error in borders (line 197)
h = plotm(lat,lon,varargin{:});

sara abdali



Thanks for your effort.

niccolo dematteis

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

Sourangsu Chowdhury


Would be great if you could also include the Chinese provinces, analogous to the US states. Note that
is not fully compatible as the country borders of China are slightly different.


Ehsan Modiri

Vinit Sehgal

Martin Fuchs

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
uistack(h,'top') % brings pcolor to the top

eko supriyadi

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

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

Sébastien MAILFERT

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?

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;

axis([0 360 -90 90])

Dillon Amaya

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

Catubela matlab

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

Vadim Poskakukhin

henyan deng


John Ryan


Fernando Ferreira

Yuecheng Zhao

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

Jan K. S.

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

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

Farhad Sedaghati


Luís Silva

Jianzhi Dong

Thank you for sharing.
How could I plot the boundary of the entire Europe?

Casper Volger

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

Then add the lat,lon locations of platforms by


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

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

Casper Volger

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!


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


Chad Greene

Hi Marina,

For a list of countries type

load borderdata.mat

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

and add this under "switch plotWhat"

case 'latin america'
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!


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

Md Atiqul Islam

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


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

Barnaby Dobson

Maxime Hervo

Chad Greene

Jinny, It's not a wonderful solution but this works:

bd = load('borderdata.mat');

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.

Behnam Zakeri

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

Kaustubh Thirumalai

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!