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

精选内容


边栏推荐
- Compiled on unbutu with wiringPi library and run on Raspberry Pi
- HCIP(15)
- 纽约大学等 | TM-Vec:用于快速同源检测和比对的模版建模向量
- 链式编程、包、访问权限
- 测试
- lua entry case combat 123DIY
- sqlserver cannot connect remotely
- [Data analysis] Based on matlab GUI student achievement management system [including Matlab source code 1981]
- SC7A20 (Silan Micro-Accelerometer) Example
- The fledgling Xiao Li's 113th blog project notes: Wisdom cloud smart flower watering device combat (2) - basic Demo implementation
猜你喜欢

纽约大学等 | TM-Vec:用于快速同源检测和比对的模版建模向量

开源项目站点必备&交流区功能

【Make YOLO Great Again】YOLOv1-v7全系列大解析(Neck篇)

Replacing the Raspberry Pi Kernel

IDEA无法识别module(module右下角没有蓝色小方块)

【消息通知】用公众号模板消息怎么样?
![leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]](/img/b9/7bd33bd981ace25e3bbfc7be9117ff.png)
leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]

YOLO怎么入门?怎么实现自己的训练集?

解决安装MySQL后,Excel打开很慢的问题

IDEA修改注释字体
随机推荐
【历史上的今天】7 月 31 日:“缸中之脑”的提出者诞生;Wi-Fi 之父出生;USB 3.1 标准发布
Soft Exam Senior System Architect Series: Basic Knowledge of System Development
Ordinary users cannot access HGFS directory
Talking about hardware device computing storage and data interaction
Parse the bootargs from the device tree (dtb format data)
RTL8762DK uses DebugAnalyzer (four)
Fat interface in JQESAP system
What is the meaning of JS timestamp?Know SQL will consider to add a timestamp, JS timestamp for the scene?
Key Points Estimation and Point Instance
树莓派 的 arm 版的 gcc 安装 和环境变量的配置
785. Quick Sort
MYSQL logical architecture
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 "*"
Inheritance Considerations
初出茅庐的小李第112篇博客项目笔记之机智云智能浇花器实战(1)-基础Demo实现
【元胞自动机】基于matlab界面聚合元胞自动机模拟【含Matlab源码 2004期】
[cellular automata] based on matlab interface aggregation cellular automata simulation [including Matlab source code 2004]
New York University et al | TM-Vec: Template Modeling Vectors for Rapid Homology Detection and Alignment
在打开MYSQL表时,有的可以显示编辑,有的没有,如何设置。
Solve the problem that Excel opens very slowly after installing MySQL