Skip to main content

Data visualization tools for Python.

Project description

DataV

PyPI PyPI - Python Version PyPI - Wheel PyPI - Downloads License

This is an unofficial solution to draw map using Aliyun's DataV.GeoAtlas.

这是一个非官方的使用阿里云 DataV.GeoAtlas 绘制地图的解决方案。

Examples

See examples for more.

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
from matplotlib.transforms import offset_copy
from matplotlib.font_manager import FontProperties

from datav import DataVGeoAtlasFeature

# Windows 下字体可以不用这么麻烦,直接 rc 设置 SimSun 即可
simsun = FontProperties(fname="/mnt/c/Windows/Fonts/simsun.ttc")

proj = ccrs.PlateCarree()
fig = plt.figure(figsize=(14, 7))
main_box = (80.5, 82, 40.25, 41)
ax_main = plt.subplot(1, 1, 1, projection=proj)
ax_main.set_extent(main_box, crs=ccrs.PlateCarree())
ax_main.add_feature(DataVGeoAtlasFeature(659002, facecolor="darkgreen", alpha=0.2))  # 阿拉尔
ax_main.add_feature(cfeature.LAKES)
ax_main.add_feature(cfeature.RIVERS)
site = (81.196, 40.624)
ax_main.plot(
    *site,
    marker="o",
    color="green",
    markersize=10,
    transform=ccrs.Geodetic(),
)
geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax_main)
text_transform = offset_copy(geodetic_transform, units="dots", x=-25)
ax_main.text(
    site[0],
    site[1] + 0.03,
    "试验站",
    transform=text_transform,
    fontproperties=simsun,
)
xmain = np.linspace(*main_box[:2], 4)
ymain = np.linspace(*main_box[2:], 4)
ax_main.gridlines(xlocs=xmain, ylocs=ymain, linestyle=":")
# set custom formatting for the tick labels
ax_main.xaxis.set_major_formatter(LONGITUDE_FORMATTER)
ax_main.yaxis.set_major_formatter(LATITUDE_FORMATTER)
ax_main.yaxis.tick_right()
ax_main.set_xticks(xmain, crs=ccrs.PlateCarree())
ax_main.set_yticks(ymain, crs=ccrs.PlateCarree())

ax_inset = fig.add_axes([0, 0.6, 0.3, 0.35], projection=proj)
ax_inset.set_extent((73, 136, 2, 51))
ax_inset.add_feature(
    DataVGeoAtlasFeature(100000, full=True, facecolor="lightgreen", edgecolor="gray")
)
ax_inset.add_feature(DataVGeoAtlasFeature(650000, facecolor="limegreen"))
ax_inset.add_feature(DataVGeoAtlasFeature(652900, facecolor="green", edgecolor="none"))
ax_inset.add_feature(
    DataVGeoAtlasFeature(659002, facecolor="darkgreen", edgecolor="black")
)
xinset = np.linspace(73, 136, 5)
yinset = np.linspace(2, 51, 5)
ax_inset.gridlines(xlocs=xinset, ylocs=yinset, linestyle=":")
ax_inset.xaxis.set_major_formatter(LONGITUDE_FORMATTER)
ax_inset.yaxis.set_major_formatter(LATITUDE_FORMATTER)
ax_inset.xaxis.tick_top()
# set inset tick labels
ax_inset.set_xticks(xinset, crs=ccrs.PlateCarree())
ax_inset.set_yticks(yinset, crs=ccrs.PlateCarree())

plt.savefig("research_site.png", dpi=800)

Research site

Requirements

  1. Cartopy (for ploting)
  2. Geopandas (for parsing geojson)

NOTE

Free For Educational Use. Respect Aliyun's license.

仅供学习使用。遵守阿里云的协议。请合理使用地图数据。数据内容和本人无关。数据具体用途也和本人无关。请遵守相关法律规定。

TODO

  1. respect the HTTP header last-modified

    尊重 HTTP 请求头 last-modified

  2. Chinese name alias for adcode

    使用中文名替代 adcode 查询

  3. More features such as line

    从 GeoJSON 中提取更多可定制的 feature。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datav-0.2.1.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

datav-0.2.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file datav-0.2.1.tar.gz.

File metadata

  • Download URL: datav-0.2.1.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for datav-0.2.1.tar.gz
Algorithm Hash digest
SHA256 272eeec2a4e35e063ec15b70d2003859b4f3995bac8c6187583566219ef540d4
MD5 4acd8609f74835f84688a3a573155ae0
BLAKE2b-256 61c0f715ff5c61d0e21101cfd040dff3949bc86ca20587a7084fe486295531ac

See more details on using hashes here.

File details

Details for the file datav-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: datav-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for datav-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bc035cf382ffdffaaff6fcadab9df51c004bcbecb13047c1cca18e77c395def
MD5 dad6c4a79d3a70e914cc5c9d340ebd24
BLAKE2b-256 be57f598b2722f67486986fd1f823d42f50c825228b7645e75dabf337a3a3148

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page