社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

r-beginners

r-beginners 最近创建的主题
r-beginners 最近回复了
5 年前
回复了 r-beginners 创建的主题 » 如何使用Python在地图上绘制线字符串?

使用 examples 以及来自官方的数据 reference ,我已经替换了您的问题,并确定了阻止绘制线段的问题。您需要指定一列文本,指示要设置颜色的组。因此,将颜色设置为数据中的组键列。

import plotly.express as px
import pandas as pd

df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
df_airports.head()

df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
df_flight_paths.sort_values('cnt', ascending=False, inplace=True)

df_flight_paths = df_flight_paths.query("airport2 in ['DFW','LAX']")

df_flight_paths.head()
start_lat   start_lon   end_lat     end_lon     airline     airport1    airport2    cnt
33  33.942536   -118.408074     32.895951   -97.0372    AA  LAX     DFW     914
50  29.533694   -98.469778  32.895951   -97.0372    AA  SAT     DFW     826
44  41.979595   -87.904464  32.895951   -97.0372    AA  ORD     DFW     825
20  30.194533   -97.669872  32.895951   -97.0372    AA  AUS     DFW     820
19  33.640444   -84.426944  32.895951   -97.0372    AA  ATL     DFW     580

fig = px.line_mapbox(df_flight_paths,
                     lat="start_lat", 
                     lon="start_lon", 
                     color="airport2",
                     hover_name="airport1",
                     #animation_frame="time",
                     center =dict(lon=-97.0,lat=38.0),
                     zoom=3, height=600
                    )

fig.update_layout(mapbox_style="stamen-terrain",
                  mapbox_zoom=4,
                  mapbox_center_lon=-97.0,
                  mapbox_center_lat=38.0,
                  margin={"r":0,"t":0,"l":0,"b":0}
                 )

fig.show()

enter image description here