Hướng dẫn Matplotlib: Đưa Bản đồ Quốc gia của Bạn lên một Mức độ Khác – Đăng ký bản tin bởi Oscar Leo. Sed ut perspiciatis unde. Đăng ký Hướng dẫn Matplotlib Cách vẽ bản đồ đẹp với Python và Matplotlib. Bản đồ do tác giả tạo – Matplotlib đã xuất bảnQuả thật, tôi đã tạo bản đồ trên bằng cách sử dụng Matplotlib và tôi sẽ chỉ cho bạn cách làm trong hướng dẫn này. Ý tưởng là tạo ra một chức năng có thể tái sử dụng và linh hoạt cho phép tôi vẽ ngay lập tức một bản đồ đẹp của bất kỳ khu vực nào. Với một chức năng như vậy, tôi có thể tiết kiệm rất nhiều thời gian khi muốn tạo biểu đồ hoặc hình đồ với yếu tố địa lý. Tôi cũng muốn cho thấy sức mạnh của mã có thể tái sử dụng, vì nhiều lập trình viên làm việc với trực quan hóa dữ liệu quên đi các quy ước tốt nhất như vậy. Hướng dẫn này chứa mọi dòng mã bạn cần để tạo ra bản đồ Châu Phi như trên. Hãy bắt đầu. Bước 1: Tải dữ liệu địa lý Thứ duy nhất bạn cần làm trước khi bắt đầu hướng dẫn là tải dữ liệu địa lý từ đây: World Boundaries GeoJSON — Very High Resolution Đó là các ranh giới chính thức từ Ngân hàng Thế giới và là một tập dữ liệu công cộng bạn có thể sử dụng bất cứ cách nào bạn muốn. Bước 2: Nhập thư viện Như thường lệ, chúng ta bắt đầu bằng cách nhập các thư viện cần thiết, và chúng ta không cần nhiều. Vì chúng ta có dữ liệu địa lý, chúng ta muốn sử dụng geopandas để làm cho việc vẽ biểu đồ dễ dàng nhất có thể. import numpy as npimport pandas as pdimport seaborn as snsimport geopandas as gpdimport matplotlib.pyplot as pltimport matplotlib.patheffects as PathEffectsfrom matplotlib.patches import Polygon Một import mà bạn có thể chưa thấy là PathEffe. Tôi sẽ sử dụng nó để tạo ra viền xung quanh nhãn quốc gia sau này. Bước 3: Tạo một Phong cách seaborn Trước khi vẽ, tôi luôn tạo một phong cách seaborn để đạt được giao diện thống nhất. Ở đây, tôi chỉ định màu nền, font_family và text_color. Tôi đặt nền màu xanh nhạt để đại diện cho đại dương. font_family = “sans”background_color = “#D4F1F4″text_color = “#040303″sns.set_style({“axes.facecolor”: background_color… Link nguồn
Matplotlib Tutorial
How to draw beautiful maps with Python and Matplotlib


Yes, I created the map above using Matplotlib, and I’ll show you how in this tutorial.
The idea is to create a reusable and flexible function that allows me to instantly draw a beautiful map of any area.
With such a function, I can save a ton of time when I want to create charts or infographics with a geographical component.
I also want to show the power of reusable code since many programmers working with data visualization forget about such best practices.
This tutorial contains every single line of code you need to create the map of Africa above.
Let’s get started.
Step 1: Download geo data
The only thing you need to do before you can start the tutorial is to download geo data from here:
World Boundaries GeoJSON — Very High Resolution
It’s the official boundaries from the World Bank and a public dataset you can use however you want.
Step 2: Import libraries
As usual, we start by importing the necessary libraries, and we don’t need many. Since we have geographical data, we want geopandas
to make plotting as easy as possible.
import numpy as np
import pandas as pd
import seaborn as sns
import geopandas as gpd
import matplotlib.pyplot as pltimport matplotlib.patheffects as PathEffects
from matplotlib.patches import Polygon
One import that you might have yet to see is PathEffe
. I will use that to create a border around the country labels later.
Step 3: Create a seaborn style
Before plotting, I always create a seaborn style to get a coherent look. Here, I only define a background_color
, font_family
, and text_color
. I’m setting the background to light blue to represent the ocean.
font_family = "sans"
background_color = "#D4F1F4"
text_color = "#040303"sns.set_style({
"axes.facecolor": background_color…
[ad_2]