当前位置:网站首页>This map drawing tool is amazing, I recommend it~~
This map drawing tool is amazing, I recommend it~~
2022-08-01 02:35:00 【The Way of Python Data】
来源:DataCharm
Previously, the editor introduced a number of articles about the drawing of spatial visualization charts in the public account,Liked by many students,But there are also many students who say noPython的版本,Today, the editor recommends an awesome academic research map visualization tool-Python-pygmt库,顾名思义,pygmtIt is based on the powerful drawing functionGMT软件,且使用pygmt前必须安装GMT(Generic Mapping Tools)软件.GMT具体安装步骤可参考:GMT中文手册[1].需要注意的是,现阶段pygmt还不能完全支持GMTAll chart types that can be drawn,Subsequent updates will continue to improve.This tweet is mostly rightPython-pygmt的一个介绍,主要内容如下:
Python-pygmt安装
Python-pygmt 示例绘制
Python-pygmt安装
The reason why it is specially introduced herepygmt库安装,Because the library is best to useAnaconda进行安装,And need to be done separatelypygmt运行环境的搭建.pygmtThe recommended installation script statement on the official website is as follows(默认GMT已安装):
conda create --name pygmt --channel conda-forge pygmt
Activate the one you just built using the following statementpygmt虚拟环境:
conda activate pygmt
「注意」:Here I recommend using itPythonWhen doing space charting,It is best to build the virtual environment separately,Avoid dependency library version conflicts.
Python-pygmt 示例绘制
This part of the editor mainly introducespygmtThe main types of charts that can be drawn at this stage,主要内容如下:
Shorelines(海岸线)
fig = pygmt.Figure()
fig.basemap(region="g", projection="W15c", frame=True)
fig.coast(shorelines=True)
fig.show()
data points(气泡图)
fig = pygmt.Figure()
fig.basemap(region=region, projection="M15c", frame=True)
fig.coast(land="black", water="skyblue")
pygmt.makecpt(cmap="viridis", series=[data.depth_km.min(), data.depth_km.max()])
fig.plot(
x=data.longitude,
y=data.latitude,
size=0.02 * 2**data.magnitude,
color=data.depth_km,
cmap=True,
style="cc",
pen="black",
)
fig.colorbar(frame='af+l"Depth (km)"')
fig.show()
map with contour lines
fig = pygmt.Figure()
fig.grdimage(
grid=grid,
cmap="haxby",
projection="M10c",
frame=True,
)
fig.grdcontour(
annotation=1000,
interval=250,
grid=grid,
limit=[-4000, -2000],
)
fig.show()
Roads
import geopandas as gpd
import pygmt
# Read shapefile data using geopandas
gdf = gpd.read_file(
"http://www2.census.gov/geo/tiger/TIGER2015/PRISECROADS/tl_2015_15_prisecroads.zip"
)
# The dataset contains different road types listed in the RTTYP column,
# here we select the following ones to plot:
roads_common = gdf[gdf.RTTYP == "M"] # Common name roads
roads_state = gdf[gdf.RTTYP == "S"] # State recognized roads
roads_interstate = gdf[gdf.RTTYP == "I"] # Interstate roads
fig = pygmt.Figure()
# Define target region around O'ahu (Hawai'i)
region = [-158.3, -157.6, 21.2, 21.75] # xmin, xmax, ymin, ymax
title = r"Main roads of O\047ahu (Hawai\047i)" # \047 is octal code for '
fig.basemap(region=region, projection="M12c", frame=["af", f'WSne+t"{title}"'])
fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black")
# Plot the individual road types with different pen settings and assign labels
# which are displayed in the legend
fig.plot(data=roads_common, pen="5p,dodgerblue", label="CommonName")
fig.plot(data=roads_state, pen="2p,gold", label="StateRecognized")
fig.plot(data=roads_interstate, pen="2p,red", label="Interstate")
# Add legend
fig.legend()
fig.show()
Blockmean
import pygmt
# Load sample data
data = pygmt.datasets.load_sample_data(name="japan_quakes")
# Select only needed columns
data = data[["longitude", "latitude", "depth_km"]]
# Set the region for the plot
region = [130, 152.5, 32.5, 52.5]
# Define spacing in x and y direction (150 by 150 minute blocks)
spacing = "150m"
fig = pygmt.Figure()
# Calculate mean depth in km from all events within 150x150 minute
# bins using blockmean
df = pygmt.blockmean(data=data, region=region, spacing=spacing)
# convert to grid
grd = pygmt.xyz2grd(data=df, region=region, spacing=spacing)
fig.grdimage(
grid=grd,
region=region,
frame=["af", '+t"Mean earthquake depth inside each block"'],
cmap="batlow",
)
# plot slightly transparent landmasses on top
fig.coast(land="darkgray", transparency=40)
# plot original data points
fig.plot(
x=data.longitude, y=data.latitude, style="c0.3c", color="white", pen="1p,black"
)
fig.colorbar(frame=["x+lkm"])
fig.shift_origin(xshift="w+5c")
# Calculate number of total locations within 150x150 minute bins via
# blockmean's summary parameter
df = pygmt.blockmean(data=data, region=region, spacing=spacing, summary="n")
grd = pygmt.xyz2grd(data=df, region=region, spacing=spacing)
fig.grdimage(
grid=grd,
region=region,
frame=["af", '+t"Number of points inside each block"'],
cmap="batlow",
)
fig.coast(land="darkgray", transparency=40)
fig.plot(
x=data.longitude, y=data.latitude, style="c0.3c", color="white", pen="1p,black"
)
fig.colorbar(frame=["x+lcount"])
fig.show()
The above is a brief introduction to thePython-pygmtThe library is commonly used in scientific research mapping types,More other chart types,大家可参考:Python-pygmt官网例子[2]
总结
Today's tweet,小编介绍了PythonA powerful mapping tool in the language-pygmt,The library is powerful based on drawingGMT工具,与之相比,Drawing scripts are simpler and easier to understand,Interested friends can study hard,The editor will also include the library drawing with a map type~~
参考资料
[1]
GMT中文手册: https://docs.gmt-china.org/latest/.
[2]Python-pygmt官网例子: https://www.pygmt.org/latest/gallery/index.html.
-------- End --------

精选内容


边栏推荐
- Introduction to machine learning how to?
- 项目越写越大,我是这样做拆分的
- OSD read SAP CRM One Order application log way of optimization
- 链式编程、包、访问权限
- YOLO怎么入门?怎么实现自己的训练集?
- Unity3D study notes 10 - texture array
- How to get started with YOLO?How to implement your own training set?
- IDEA 找不到或无法加载主类 或 Module “*“ must not contain source root “*“ The root already belongs to module “*“
- After specifying set 'execution.savepoint.path', restart flinksql and report this error
- What is the meaning of JS timestamp?Know SQL will consider to add a timestamp, JS timestamp for the scene?
猜你喜欢
Academicians of the two academies speak bluntly: Don't be superstitious about academicians
Summary of MVCC
LeetCode每日一练 —— 环形链表问题(面试四连问)
What practical projects can machine learning beginners learn?
设备树——dtb格式到struct device node结构体的转换
【入门教程】Rollup模块打包器整合
The fledgling Xiao Li's 112th blog project notes: Wisdom cloud intelligent flower watering device actual combat (1) - basic Demo implementation
How to get started with YOLO?How to implement your own training set?
Unity3D study notes 10 - texture array
RTL8762DK RTC (5)
随机推荐
By CSDN, torn
Solve the problem that when IDEA creates a new file by default, right-click, new, there is no XML file
gateway gateway cross domain
Compiled on unbutu with wiringPi library and run on Raspberry Pi
【Make YOLO Great Again】YOLOv1-v7全系列大解析(Neck篇)
IDEA debugging
HCIP (14)
HCIP(15)
C string array reverse
Basic implementation of vector
树莓派 的 arm 版的 gcc 安装 和环境变量的配置
JQESAP系统里的胖接口Fat interface
从设备树(dtb格式数据)中解析出bootargs
RTL8762DK Lighting/LED (3)
普通用户无法访问hgfs目录
Js replication
Detailed explanation of TCP protocol
how to edit the table of contents of an epub ebook
Google engineer fired for claiming AI awareness: breach of nondisclosure agreement
彻底关闭Chrome浏览器更新及右上角的更新提示