html绘制地铁线路图,Plotly绘制成都地铁全线路图(线路可实时更新最新线路 + 完整代码)...

这篇博客通过Python从百度地图API获取成都地铁站信息,使用Plotly库绘制地铁线路图,同时进行了坐标转换。代码中包含了数据解析、坐标系统转换等步骤,最终将结果保存为CSV和Excel文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

Created on Fri Nov 6 11:16:45 2020

Chengdu Metro Lines by plotly with python

@author: 进击的SB

"""

import requests

import time

import numpy as np

import math

# import plotly.offline as py

# import plotly.graph_objs as go

import pandas as pd

PI = math.pi

null = None

city_code=75

station_info = requests.get('http://map.baidu.com/?qt=bsi&c=%s&t=%s' % (

city_code,

int(time.time() * 1000)

))

station_info_json = eval(station_info.content)

# print(station_info_json)

# 解析地铁线路站点信息

for line in station_info_json['content']:

# i = 0

plots = []

plots_name = []

for plot in line['stops']:

plots.append([plot['x'], plot['y']])

plots_name.append(plot['name'])

# print(plots)

plot_mercator = np.array(plots)

def _transformlat(coordinates):

lng = coordinates[ : , 0] - 105

lat = coordinates[ : , 1] - 35

ret = -100 + 2 * lng + 3 * lat + 0.2 * lat * lat +

0.1 * lng * lat + 0.2 * np.sqrt(np.fabs(lng))

ret += (20 * np.sin(6 * lng * PI) + 20 *

np.sin(2 * lng * PI)) * 2 / 3

ret += (20 * np.sin(lat * PI) + 40 *

np.sin(lat / 3 * PI)) * 2 / 3

ret += (160 * np.sin(lat / 12 * PI) + 3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值