Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw your own world map by Python

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces Python how to draw your world map, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Python is so popular because it can be used not only in science and technology, but also as a research tool in many other disciplines, the most common of which is mapping.

Today we use one of the matplot toolkits: mpl_toolkits to map the world, which is a simple visualization tool. If you want to make more complex maps, you can consider using Google Maps API, but this is beyond the scope of our discussion today.

1. Installation

If you have not already installed Python, please see this article: hyperdetailed Python installation Guide

In order to run the project smoothly, you need to install the following dependencies and enter the following command in cmd or Terminal:

Pip install numpy

Pip install matplotlib

In order to use mpl_toolkits, simply installing matplotlib is not enough. We also need to install basemap separately. If you have already installed Anaconda, this step is very easy. Enter the following command to install it:

Conda install basemap

If not, it's a little more troublesome:

1. Install geos: pip install geos

two。 Download basemap based on your Python version

Http://www.lfd.uci.edu/~gohlke/pythonlibs/#basemap

Note that the number after cp is the version of Python. (press ctrl+F on the page and enter basemap for quick positioning)

3. Go to the directory of the file under cmd and run

Pip install basemap-1.2.1-cp37-cp37m-win_amd64.whl

two。 Simple map

Let's start drawing an earth with the center pointing to China:

The focus here is on Basemap, which specifies the center you want to place.

The effect is not bad, not only that, it is not just an image, it is also a fully functional matplot canvas. This means that you can draw a line on it! Let's enlarge the map, enter the Chinese area, and then mark the location of Shenzhen:

Don't use the blue background picture, it's not very clear, let's change it to an embossed one:

The geographical features such as mountains and hills can be clearly seen. You can also connect several cities or draw areas between latitudes and longitudes according to your needs. Don't forget, this is a matplotlib editable canvas.

3. World map

Next, we expand the above world map into a plane graph with longitude and latitude.

Well, it smells a little bit. You can print it out by yourself to learn geography for children. But if he wants to study geography, it seems that the whole world is a little big. Shall we let him learn the location of the world-famous scenic spots first?

Zoom in to see:

In this way, you only need to add the latitude and longitude of a location to the locations, and you can show it on the map, and you can also draw a custom line between two locations, or focus on a certain area. In short, you can do basically anything you want to do based on Matplotlib.

If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report