最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python用folium繪制地圖并設(shè)置彈窗效果

 更新時(shí)間:2021年09月02日 10:04:18   作者:KaZaKun  
這篇文章主要介紹了python用folium繪制地圖并設(shè)置彈窗,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

python–Folium

官方說明:folium.link.

  • map用于生成地圖,主要用到黃色的參數(shù)

Map(location=None, width=‘100%', height=‘100%', left=‘0%', top=‘0%', position=‘relative', tiles=‘OpenStreetMap', attr=None, min_zoom=0, max_zoom=18, zoom_start=10, min_lat=- 90, max_lat=90, min_lon=- 180, max_lon=180, max_bounds=False, crs=‘EPSG3857', control_scale=False, prefer_canvas=False, no_touch=False, disable_3d=False, jpg_enabled=False, zoom_control=True, **kwargs)

Parameters 參數(shù)說明

  • location (tuple or list, default None) – Latitude and Longitude of Map (Northing, Easting).
  • width (pixel int or percentage string (default: ‘100%')) – Width of the map.
  • height (pixel int or percentage string (default: ‘100%')) – Height of the map.
  • tiles (str, default ‘OpenStreetMap') – Map tileset to use. Can choose from a list of built-in tiles, pass a custom URL or pass None to create a map without tiles. For more advanced tile layer options, use the TileLayer class.
  • min_zoom (int, default 0) – Minimum allowed zoom level for the tile layer that is created.
  • max_zoom (int, default 18) – Maximum allowed zoom level for the tile layer that is created.
  • zoom_start (int, default 10) – Initial zoom level for the map.
  • attr (string, default None) – Map tile attribution; only required if passing custom tile URL.
  • crs (str, default ‘EPSG3857') – Defines coordinate reference systems for projecting geographical points into pixel (screen) coordinates and back.定義坐標(biāo)參考系統(tǒng)
  • control_scale (bool, default False) – Whether to add a control scale on the map.
  • prefer_canvas (bool, default False) – Forces Leaflet to use the Canvas back-end (if available) for vector layers instead of SVG.
  • no_touch (bool, default False) – Forces Leaflet to not use touch events even if it detects them.
  • disable_3d (bool, default False) – Forces Leaflet to not use hardware-accelerated CSS 3D transforms for positioning (which may cause glitches in some rare environments) even if they're supported.
  • zoom_control (bool, default True) – Display zoom controls on the map.

basic example

m = folium.Map(location=[45.523, -122.675], width=750, height=500)

m = folium.Map(location=[45.523, -122.675], tiles='cartodb positron')

m = folium.Map(

   location=[45.523, -122.675],

   zoom_start=2,

   tiles='https://api.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg?access_token=mytoken',

   attr='Mapbox attribution'
...)

Markers

m = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles="Stamen Terrain")

tooltip = "Click me!"

folium.Marker(
    [45.3288, -121.6625], popup="<i>Mt. Hood Meadows</i>", tooltip=tooltip
).add_to(m)

tooltip:點(diǎn)擊標(biāo)記后彈出的信息
popup:鼠標(biāo)放標(biāo)記上顯示的信息

在這里插入圖片描述

標(biāo)記樣式修改

m = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles="Stamen Terrain")

folium.Marker(
    location=[45.3288, -121.6625],
    popup="Mt. Hood Meadows",
    icon=folium.Icon(icon="cloud"),
).add_to(m)

folium.Marker(
    location=[45.3311, -121.7113],
    popup="Timberline Lodge",
    icon=folium.Icon(color="green"),
).add_to(m)

folium.Marker(
    location=[45.3300, -121.6823],
    popup="Some Other Location",
    icon=folium.Icon(color="red", icon="info-sign"),
).add_to(m)

在這里插入圖片描述

標(biāo)記圓形區(qū)域

在這里插入圖片描述

點(diǎn)擊任意位置出現(xiàn)經(jīng)緯度folium.LatLngPopup()

m = folium.Map(location=[46.1991, -122.1889], tiles="Stamen Terrain", zoom_start=13)

m.add_child(folium.LatLngPopup())

Alt

打點(diǎn)功能:點(diǎn)擊任意位置出現(xiàn)標(biāo)記,再點(diǎn)擊彈出信息

m = folium.Map(location=[46.8527, -121.7649], tiles="Stamen Terrain", zoom_start=13)

folium.Marker([46.8354, -121.7325], popup="Camp Muir").add_to(m)

m.add_child(folium.ClickForMarker(popup="Waypoint"))

在這里插入圖片描述

允許顯示任何HTML對象

m = folium.Map(location=[46.3014, -123.7390], zoom_start=7, tiles="Stamen Terrain")

folium.Marker(
    location=[47.3489, -124.708],
    popup=folium.Popup(max_width=450).add_child(
        folium.Vega(vis1, width=450, height=250)
    ),
).add_to(m)

在這里插入圖片描述

可以參考的代碼
html參考鏈接

實(shí)戰(zhàn)

用folium繪制中國的政策地圖,城市的政策匯總在一個(gè)excel表中。要實(shí)現(xiàn)的效果是政策可視化,點(diǎn)擊某一個(gè)城市,可以彈出這個(gè)城市所有的政策。

import folium
import webbrowser as wb
import numpy as np
import xlrd
import pandas as pd
from folium import CustomIcon

def get_data():
    '''
    return:
    df_data:返回城市對應(yīng)的編號,經(jīng)緯度
    df_policy:返回城市的政策名稱、鏈接、編號
    '''
    file_name = 'policy.xls'
    all_data = xlrd.open_workbook(file_name)
    table = all_data.sheet_by_name('num_lat_lon')
    df_data = pd.DataFrame(columns=['city','number','latitude','longitude'])
    for i in range(1,table.nrows):
        df_data.loc[i] = table.row_values(i)

    table_policy = all_data.sheet_by_name('policy')
    df_policy = pd.DataFrame(columns=['number','name','link'])
    for i in range(1,table_policy.nrows):
        df_policy.loc[i,'number'] = table_policy.cell(i,3).value
        df_policy.loc[i,'name'] = table_policy.cell(i,1).value
        df_policy.loc[i,'link'] = table_policy.cell(i,2).value

    return df_data, df_policy

    # 中文轉(zhuǎn)換
def parse_zhch(s):
        return str(str(s).encode('ascii' , 'xmlcharrefreplace'))[2:-1]

def show_map(df_data,df_policy):
    '''
    可以使用高德地圖或默認(rèn)地圖
    m = folium.Map(zoom_start=4,zoom_control=True,tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',attr='default')
    '''
    # 默認(rèn)地圖
    m = folium.Map(location=[39.904,116.408],zoom_start=4,zoom_control=True,tiles='OpenStreetMap')
    for i in range(1,len(df_data)):
        # 得到該城市的編號、經(jīng)緯度
        number = df_data.loc[i,'number']
        latitude = df_data.loc[i,'latitude']
        longitude = df_data.loc[i,'longitude']
        tip = df_data.loc[i,'city']

        # 獲取城市編號對應(yīng)的所有政策和鏈接的行索引
        city_index = df_policy[df_policy.number == number].index.tolist()
        # 將城市名稱和鏈接放同一個(gè)list中
        s=[]
        for i in city_index:
            s.append(df_policy.loc[i,'name']) 
            s.append(df_policy.loc[i,'link'])
        # 計(jì)算最大長度
        length = []
        for i in range(len(s)):
            length.append(len(s[i]))
        WIDTH = max(length)
        # 點(diǎn)擊彈出內(nèi)容和彈出框大小設(shè)置
        ss=''
        for i in range(len(s)):
            ss = ss + s[i] + '</br>' 
        pop = folium.Popup(html=ss,max_width=WIDTH*10)
        icon = CustomIcon(icon_image ='loc.jpg',icon_size=(20, 20))
        # tooltip:懸浮彈出信息;popup:點(diǎn)擊出現(xiàn)信息
        folium.Marker([latitude,longitude],icon=icon, popup=pop,tooltip=parse_zhch(tip)).add_to(m)

    m.save('map.html')
    wb.open('map.html')


if __name__ == '__main__':

    df_data,df_policy = get_data()
    show_map(df_data,df_policy)

實(shí)現(xiàn)效果:

在這里插入圖片描述

到此這篇關(guān)于python用folium繪制地圖并設(shè)置彈窗效果的文章就介紹到這了,更多相關(guān)python folium繪制地圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python爬蟲:將headers請求頭字符串轉(zhuǎn)為字典的方法

    Python爬蟲:將headers請求頭字符串轉(zhuǎn)為字典的方法

    今天小編就為大家分享一篇Python爬蟲:將headers請求頭字符串轉(zhuǎn)為字典的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • 在Python中使用正則表達(dá)式的方法

    在Python中使用正則表達(dá)式的方法

    這篇文章主要介紹了在Python中使用正則表達(dá)式的方法,講到了專門對正則表達(dá)式提供支持的擴(kuò)展庫re,需要的朋友可以參考下
    2015-08-08
  • 記錄一下scrapy中settings的一些配置小結(jié)

    記錄一下scrapy中settings的一些配置小結(jié)

    這篇文章主要介紹了記錄一下scrapy中settings的一些配置小結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • python新手學(xué)習(xí)可變和不可變對象

    python新手學(xué)習(xí)可變和不可變對象

    在本篇文章里小編給大家分享了是一篇關(guān)于python可變對象和不可變對象的基礎(chǔ)知識點(diǎn)內(nèi)容,有需要的朋友們可以參考下。
    2020-06-06
  • Python?pickle?二進(jìn)制序列化和反序列化及數(shù)據(jù)持久化詳解

    Python?pickle?二進(jìn)制序列化和反序列化及數(shù)據(jù)持久化詳解

    這篇文章主要介紹了Python?pickle?二進(jìn)制序列化和反序列化?-?數(shù)據(jù)持久化,模塊?pickle?實(shí)現(xiàn)了對一個(gè)?Python?對象結(jié)構(gòu)的二進(jìn)制序列化和反序列化,本文介紹了Pickle的基本用法,需要的朋友可以參考下
    2024-01-01
  • python 用Matplotlib作圖中有多個(gè)Y軸

    python 用Matplotlib作圖中有多個(gè)Y軸

    這篇文章主要介紹了python 如何用Matplotlib作圖中有多個(gè)Y軸,幫助大家更好的利用python繪圖,感興趣的朋友可以了解下
    2020-11-11
  • python之yield和return的對比分析

    python之yield和return的對比分析

    這篇文章主要介紹了python之yield和return的對比分析,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • 基于Python fminunc 的替代方法

    基于Python fminunc 的替代方法

    今天小編就為大家分享一篇基于Python fminunc 的替代方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • Opencv實(shí)現(xiàn)傾斜圖片轉(zhuǎn)正示例

    Opencv實(shí)現(xiàn)傾斜圖片轉(zhuǎn)正示例

    本文主要介紹了Opencv實(shí)現(xiàn)傾斜圖片轉(zhuǎn)正示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • python爬蟲xpath模塊簡介示例代碼

    python爬蟲xpath模塊簡介示例代碼

    xpath是最常用且最便捷高效的一種解析方式,通用型強(qiáng),其不僅可以用于python語言中,還可以用于其他語言中,數(shù)據(jù)解析建議首先xpath,這篇文章主要介紹了python爬蟲xpath模塊簡介,需要的朋友可以參考下
    2023-02-02

最新評論

马鞍山市| 通道| 辽阳县| 富民县| 通河县| 卢氏县| 天柱县| 旬阳县| 双柏县| 定日县| 墨玉县| 松桃| 连江县| 本溪市| 札达县| 彭山县| 宁化县| 台北市| 景洪市| 东宁县| 娄烦县| 临桂县| 肇源县| 堆龙德庆县| 白河县| 保康县| 辽宁省| 乐至县| 禄劝| 嘉祥县| 大荔县| 嫩江县| 杂多县| 额尔古纳市| 商洛市| 唐海县| 临沭县| 孝感市| 南溪县| 叙永县| 澄迈县|