当前位置:网站首页>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 --------

精选内容


边栏推荐
- HCIP(15)
- win10 固定本机IP
- 初出茅庐的小李第114篇博客项目笔记之机智云智能浇花器实战(3)-基础Demo实现
- 彻底关闭Chrome浏览器更新及右上角的更新提示
- leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]
- Solve the problem that when IDEA creates a new file by default, right-click, new, there is no XML file
- sqlserver无法远程连接
- 机器学习应该如何入门?
- opencv 缩小放大用哪种插值更好??
- HIRO: Hierarchical Reinforcement Learning 】 【 Data - Efficient Hierarchical Reinforcement Learning
猜你喜欢
New York University et al | TM-Vec: Template Modeling Vectors for Rapid Homology Detection and Alignment
The IDEA can't find or unable to load The main class or Module "*" must not contain The source root "*" The root already belongs to The Module "*"
How to get started with YOLO?How to implement your own training set?
Beijing suddenly announced that yuan universe big news
leetcode: 1562. Find latest grouping of size M [simulation + endpoint record + range merge]
带wiringPi库在unbutu 编译 并且在树莓派运行
Talking about hardware device computing storage and data interaction
项目越写越大,我是这样做拆分的
Euler system (euleros): upgrade Mysql
【历史上的今天】7 月 31 日:“缸中之脑”的提出者诞生;Wi-Fi 之父出生;USB 3.1 标准发布
随机推荐
[cellular automata] based on matlab interface aggregation cellular automata simulation [including Matlab source code 2004]
Handwritten binary search tree and test
修改Postman安装路径
Rasa 3.x Learning Series - Using Lookup Tables to Improve Entity Extraction
WebApi 打个Attribute 统一处理异常
OSD读取SAP CRM One Order应用日志的优化方式
/usr/sbin/vmware-authdlauncher: error while loading shared libraries: libssl.so.1.0.2*Solution
Device tree - conversion from dtb format to struct device node structure
项目越写越大,我是这样做拆分的
纽约大学等 | TM-Vec:用于快速同源检测和比对的模版建模向量
lua entry case combat 123DIY
Chain programming, packages, access
树莓派 的 arm 版的 gcc 安装 和环境变量的配置
Modern Enterprise Architecture Framework 1
how to edit the table of contents of an epub ebook
OSD read SAP CRM One Order application log way of optimization
IDEA调试
RTL8762DK WDG (six)
MySQL修改SQL语句优化性能
【历史上的今天】7 月 31 日:“缸中之脑”的提出者诞生;Wi-Fi 之父出生;USB 3.1 标准发布