Plot World, Continent and Cities

Plot World, Continent and Cities

In [1]:
import geopandas
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
geopandas.datasets.available
Out[2]:
['naturalearth_lowres', 'naturalearth_cities', 'nybb']

Get world dataset

In [3]:
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
In [4]:
world.head()
Out[4]:
pop_est continent name iso_a3 gdp_md_est geometry
0 920938 Oceania Fiji FJI 8374.0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3 35623680 North America Canada CAN 1674000.0 MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4 326625791 North America United States of America USA 18560000.0 MULTIPOLYGON (((-122.84000 49.00000, -120.0000...

Plot the world

In [5]:
world.plot();

Increase plot size

In [6]:
world.plot(figsize=(15, 15))
Out[6]:
<AxesSubplot:>

set axis off

In [7]:
ax = world.plot(figsize=(15, 15))
ax.set_axis_off()

Plot world whose population is greater than zero and name is not Antarctica

In [8]:
world1 = world[(world['pop_est'] > 0 ) & (world['name'] != "Antarctica")]
world1.head()
Out[8]:
pop_est continent name iso_a3 gdp_md_est geometry
0 920938 Oceania Fiji FJI 8374.0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3 35623680 North America Canada CAN 1674000.0 MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4 326625791 North America United States of America USA 18560000.0 MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
In [9]:
ax = world1.plot(figsize=(15, 15))
ax.set_axis_off()

Plot Asia continent

In [10]:
world2 = world[(world['continent'] == "Asia")]
world2.head()
Out[10]:
pop_est continent name iso_a3 gdp_md_est geometry
5 18556698 Asia Kazakhstan KAZ 460700.0 POLYGON ((87.35997 49.21498, 86.59878 48.54918...
6 29748859 Asia Uzbekistan UZB 202300.0 POLYGON ((55.96819 41.30864, 55.92892 44.99586...
8 260580739 Asia Indonesia IDN 3028000.0 MULTIPOLYGON (((141.00021 -2.60015, 141.01706 ...
24 1291358 Asia Timor-Leste TLS 4975.0 POLYGON ((124.96868 -8.89279, 125.08625 -8.656...
76 8299706 Asia Israel ISR 297000.0 POLYGON ((35.71992 32.70919, 35.54567 32.39399...
In [11]:
ax = world2.plot(figsize=(15, 15))
ax.set_axis_off()

Plot continent which is not Asia

In [12]:
world3 = world[(world['continent'] != "Asia")]
world3.head()
Out[12]:
pop_est continent name iso_a3 gdp_md_est geometry
0 920938 Oceania Fiji FJI 8374.0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3 35623680 North America Canada CAN 1674000.0 MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4 326625791 North America United States of America USA 18560000.0 MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
In [13]:
ax = world3.plot(figsize=(15, 15))
ax.set_axis_off()

Plot United States of America

In [14]:
usa = world[world['name'] == 'United States of America']
usa.plot()
Out[14]:
<AxesSubplot:>

Plot continent United States of America

In [15]:
usaContinent = world[world['continent'] == 'North America']
usaContinent
Out[15]:
pop_est continent name iso_a3 gdp_md_est geometry
3 35623680 North America Canada CAN 1674000.0 MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4 326625791 North America United States of America USA 18560000.0 MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
16 10646714 North America Haiti HTI 19340.0 POLYGON ((-71.71236 19.71446, -71.62487 19.169...
17 10734247 North America Dominican Rep. DOM 161900.0 POLYGON ((-71.70830 18.04500, -71.68774 18.316...
19 329988 North America Bahamas BHS 9066.0 MULTIPOLYGON (((-78.98000 26.79000, -78.51000 ...
22 57713 North America Greenland GRL 2173.0 POLYGON ((-46.76379 82.62796, -43.40644 83.225...
27 124574795 North America Mexico MEX 2307000.0 POLYGON ((-117.12776 32.53534, -115.99135 32.6...
33 3753142 North America Panama PAN 93120.0 POLYGON ((-77.35336 8.67050, -77.47472 8.52429...
34 4930258 North America Costa Rica CRI 79260.0 POLYGON ((-82.54620 9.56613, -82.93289 9.47681...
35 6025951 North America Nicaragua NIC 33550.0 POLYGON ((-83.65561 10.93876, -83.89505 10.726...
36 9038741 North America Honduras HND 43190.0 POLYGON ((-83.14722 14.99583, -83.48999 15.016...
37 6172011 North America El Salvador SLV 54790.0 POLYGON ((-89.35333 14.42413, -89.05851 14.340...
38 15460732 North America Guatemala GTM 131800.0 POLYGON ((-92.22775 14.53883, -92.20323 14.830...
39 360346 North America Belize BLZ 3088.0 POLYGON ((-89.14308 17.80832, -89.15091 17.955...
45 3351827 North America Puerto Rico PRI 131000.0 POLYGON ((-66.28243 18.51476, -65.77130 18.426...
46 2990561 North America Jamaica JAM 25390.0 POLYGON ((-77.56960 18.49053, -76.89662 18.400...
47 11147407 North America Cuba CUB 132900.0 POLYGON ((-82.26815 23.18861, -81.40446 23.117...
175 1218208 North America Trinidad and Tobago TTO 43570.0 POLYGON ((-61.68000 10.76000, -61.10500 10.890...
In [16]:
usaContinent.plot()
Out[16]:
<AxesSubplot:>

Plot India

In [17]:
india = world[world['name'] == 'India']
india.plot()
Out[17]:
<AxesSubplot:>

Plot neighbouring country of India

Nepal

In [18]:
nepal = world[world['name'] == 'Nepal']
nepal.plot()
Out[18]:
<AxesSubplot:>

Pakistan

In [19]:
pakistan = world[world['name'] == 'Pakistan']
pakistan.plot()
Out[19]:
<AxesSubplot:>

Plot Africa continent

In [20]:
africa = world[world['continent'] == 'Africa']
In [21]:
africa
Out[21]:
pop_est continent name iso_a3 gdp_md_est geometry
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
11 83301151 Africa Dem. Rep. Congo COD 66010.0 POLYGON ((29.34000 -4.49998, 29.51999 -5.41998...
12 7531386 Africa Somalia SOM 4719.0 POLYGON ((41.58513 -1.68325, 40.99300 -0.85829...
13 47615739 Africa Kenya KEN 152700.0 POLYGON ((39.20222 -4.67677, 37.76690 -3.67712...
14 37345935 Africa Sudan SDN 176300.0 POLYGON ((24.56737 8.22919, 23.80581 8.66632, ...
15 12075985 Africa Chad TCD 30590.0 POLYGON ((23.83766 19.58047, 23.88689 15.61084...
25 54841552 Africa South Africa ZAF 739100.0 POLYGON ((16.34498 -28.57671, 16.82402 -28.082...
26 1958042 Africa Lesotho LSO 6019.0 POLYGON ((28.97826 -28.95560, 29.32517 -29.257...
48 13805084 Africa Zimbabwe ZWE 28330.0 POLYGON ((31.19141 -22.25151, 30.65987 -22.151...
49 2214858 Africa Botswana BWA 35900.0 POLYGON ((29.43219 -22.09131, 28.01724 -22.827...
50 2484780 Africa Namibia NAM 25990.0 POLYGON ((19.89577 -24.76779, 19.89473 -28.461...
51 14668522 Africa Senegal SEN 39720.0 POLYGON ((-16.71373 13.59496, -17.12611 14.373...
52 17885245 Africa Mali MLI 38090.0 POLYGON ((-11.51394 12.44299, -11.46790 12.754...
53 3758571 Africa Mauritania MRT 16710.0 POLYGON ((-17.06342 20.99975, -16.84519 21.333...
54 11038805 Africa Benin BEN 24310.0 POLYGON ((2.69170 6.25882, 1.86524 6.14216, 1....
55 19245344 Africa Niger NER 20150.0 POLYGON ((14.85130 22.86295, 15.09689 21.30852...
56 190632261 Africa Nigeria NGA 1089000.0 POLYGON ((2.69170 6.25882, 2.74906 7.87073, 2....
57 24994885 Africa Cameroon CMR 77240.0 POLYGON ((14.49579 12.85940, 14.89336 12.21905...
58 7965055 Africa Togo TGO 11610.0 POLYGON ((0.89956 10.99734, 0.77234 10.47081, ...
59 27499924 Africa Ghana GHA 120800.0 POLYGON ((0.02380 11.01868, -0.04978 10.70692,...
60 24184810 Africa Côte d'Ivoire CIV 87120.0 POLYGON ((-8.02994 10.20653, -7.89959 10.29738...
61 12413867 Africa Guinea GIN 16080.0 POLYGON ((-13.70048 12.58618, -13.21782 12.575...
62 1792338 Africa Guinea-Bissau GNB 2851.0 POLYGON ((-16.67745 12.38485, -16.14772 12.547...
63 4689021 Africa Liberia LBR 3881.0 POLYGON ((-8.43930 7.68604, -8.48545 7.39521, ...
64 6163195 Africa Sierra Leone SLE 10640.0 POLYGON ((-13.24655 8.90305, -12.71196 9.34271...
65 20107509 Africa Burkina Faso BFA 32990.0 POLYGON ((-5.40434 10.37074, -5.47056 10.95127...
66 5625118 Africa Central African Rep. CAF 3206.0 POLYGON ((27.37423 5.23394, 27.04407 5.12785, ...
67 4954674 Africa Congo COG 30270.0 POLYGON ((18.45307 3.50439, 18.39379 2.90044, ...
68 1772255 Africa Gabon GAB 35980.0 POLYGON ((11.27645 2.26105, 11.75167 2.32676, ...
69 778358 Africa Eq. Guinea GNQ 31770.0 POLYGON ((9.64916 2.28387, 11.27645 2.26105, 1...
70 15972000 Africa Zambia ZMB 65170.0 POLYGON ((30.74001 -8.34001, 31.15775 -8.59458...
71 19196246 Africa Malawi MWI 21200.0 POLYGON ((32.75938 -9.23060, 33.73972 -9.41715...
72 26573706 Africa Mozambique MOZ 35010.0 POLYGON ((34.55999 -11.52002, 35.31240 -11.439...
73 1467152 Africa eSwatini SWZ 11060.0 POLYGON ((32.07167 -26.73382, 31.86806 -27.177...
74 29310273 Africa Angola AGO 189000.0 MULTIPOLYGON (((12.99552 -4.78110, 12.63161 -4...
75 11466756 Africa Burundi BDI 7892.0 POLYGON ((30.46967 -2.41385, 30.52766 -2.80762...
78 25054161 Africa Madagascar MDG 36860.0 POLYGON ((49.54352 -12.46983, 49.80898 -12.895...
80 2051363 Africa Gambia GMB 3387.0 POLYGON ((-16.71373 13.59496, -15.62460 13.623...
81 11403800 Africa Tunisia TUN 130800.0 POLYGON ((9.48214 30.30756, 9.05560 32.10269, ...
82 40969443 Africa Algeria DZA 609400.0 POLYGON ((-8.68440 27.39574, -8.66512 27.58948...
154 5918919 Africa Eritrea ERI 9169.0 POLYGON ((36.42951 14.42211, 36.32322 14.82249...
162 33986655 Africa Morocco MAR 282800.0 POLYGON ((-2.16991 35.16840, -1.79299 34.52792...
163 97041072 Africa Egypt EGY 1105000.0 POLYGON ((36.86623 22.00000, 32.90000 22.00000...
164 6653210 Africa Libya LBY 90890.0 POLYGON ((25.00000 22.00000, 25.00000 20.00304...
165 105350020 Africa Ethiopia ETH 174700.0 POLYGON ((47.78942 8.00300, 44.96360 5.00162, ...
166 865267 Africa Djibouti DJI 3345.0 POLYGON ((42.35156 12.54223, 42.77964 12.45542...
167 3500000 Africa Somaliland -99 12250.0 POLYGON ((48.94820 11.41062, 48.94820 11.41062...
168 39570125 Africa Uganda UGA 84930.0 POLYGON ((33.90371 -0.95000, 31.86617 -1.02736...
169 11901484 Africa Rwanda RWA 21970.0 POLYGON ((30.41910 -1.13466, 30.81613 -1.69891...
176 13026129 Africa S. Sudan SSD 20880.0 POLYGON ((30.83385 3.50917, 29.95350 4.17370, ...
In [22]:
africa.plot()
Out[22]:
<AxesSubplot:>

Download the cities data

In [23]:
cities = geopandas.read_file(
    geopandas.datasets.get_path("naturalearth_cities")
)
In [24]:
cities
Out[24]:
name geometry
0 Vatican City POINT (12.45339 41.90328)
1 San Marino POINT (12.44177 43.93610)
2 Vaduz POINT (9.51667 47.13372)
3 Luxembourg POINT (6.13000 49.61166)
4 Palikir POINT (158.14997 6.91664)
... ... ...
197 Cairo POINT (31.24802 30.05191)
198 Tokyo POINT (139.74946 35.68696)
199 Paris POINT (2.33139 48.86864)
200 Santiago POINT (-70.66899 -33.44807)
201 Singapore POINT (103.85387 1.29498)

202 rows × 2 columns

Plot cities on world map

In [25]:
ax = world.plot(figsize=(15, 15))
cities.plot(ax=ax, color='red', markersize=10)
ax.set_axis_off()

Plot Paris on the world map

In [26]:
paris = cities[cities['name'] == 'Paris']
paris.plot()
Out[26]:
<AxesSubplot:>
In [27]:
ax = world.plot(figsize=(15, 15))
paris.plot(ax=ax, color='red', markersize=10)
ax.set_axis_off()

Plot Singapore

In [28]:
singapore = cities[cities['name'] == 'Singapore']
singapore.plot()
Out[28]:
<AxesSubplot:>
In [29]:
ax = world.plot(figsize=(15, 15))
singapore.plot(ax=ax, color='red', markersize=20)
ax.set_axis_off()

Plot New Delhi city on India map

In [30]:
delhi = cities[cities['name'] == 'New Delhi']
delhi.plot()
Out[30]:
<AxesSubplot:>
In [31]:
ax = india.plot(figsize=(15, 15))
delhi.plot(ax=ax, color='red', markersize=20)
ax.set_axis_off()

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing