Plotly滑块热图速度较慢

2024-09-28 03:12:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我写这段代码是为了制作加拿大的热图,其中有一个滑块用于不同的“轮”(时间实例)。它运行得很好,但运行6轮需要10分钟,但运行更多轮(如50轮)需要很多小时。有没有什么可以加快它的速度,比如格式化或JSON读取


import json
import plotly.express as px
import plotly.offline as pyo
import pandas as pd


df = pd.read_csv('/Users/....csv')
df["Product Number"] = df["Product Number"].str[:5]
df = df.dropna(axis=0, subset=['$perMHz-Pop (Posted)'])

df_openmhzpop = df.loc[df['Category'] == 'Open']
df_setasidemhzpop = df.loc[df['Category']== 'Set-Aside']


ca_tier4 = json.load(open(r"/Users/...CATier4.json", 'r', encoding='ISO-8859-1'))

fig_openmhzpop = px.choropleth_mapbox(df_openmhzpop, geojson=ca_tier4, locations ='Product Number', color='$perMHz-Pop (Posted) for Plot',
                            hover_data=["Round", "Product Number", "Category", "Service Area Name", "Start Price", "(Initial) Supply", "Aggregate Demand", "Excess Demand", "$perMHz-Pop (Posted)"],
                            range_color=(0,1.2), mapbox_style="carto-positron",
                            zoom=2.5, center={"lat": 63.0902, "lon": -95.7129},
                            opacity=1, animation_frame='Round', color_continuous_midpoint=0.5, 
                            color_continuous_scale=["red", "white", "rgb(27,158,119)"])



fig_openmhzpop.layout.coloraxis.colorbar.title = '$perMHz-Pop (Posted)'

fig_openmhzpop.write_html(r'C:\Users...Open.html')

enter image description here


Tags: importjsonnumberdfasfigplotlyproduct

热门问题