gpt4 book ai didi

Python Altair 渲染错误 - Javascript 错误 : too much recursion

转载 作者:行者123 更新时间:2023-12-04 03:31:11 24 4
gpt4 key购买 nike

我将 Altair 图表用于 Python 和 Jupyter 笔记本,但是如果我增加数据点的数量,其中一个(渲染?)组件会崩溃:

import altair as alt
import datetime
import pandas as pd
import random

def add_minutes(tm, minutes_to_add):
fulldate = datetime.datetime(100, 1, 1, tm.hour, tm.minute, tm.second)
fulldate = fulldate + datetime.timedelta(minutes=minutes_to_add)
return fulldate.time()

time_sort_order = []

render_hours = 13

def build_df():
value_list = []
start_time = datetime.time(21, 0, 0)
for n in range(60*render_hours):
time_to_fetch = add_minutes(start_time, 1*n)
time_sort_order.append(str(time_to_fetch))
value_list.append({
"time": str(time_to_fetch),
"value": random.randint(1, 5)
})
return pd.DataFrame(value_list)

df = build_df()

alt.Chart(df).mark_rect().encode(
x=alt.X('time', sort=time_sort_order),
color='value:Q'
)

如果我设置 render_hours = 13:一切正常工作/呈现

如果我设置 render_hours = 14:我得到一个空白输出

如果我设置 render_hours = 24:

Javascript Error: too much recursion This usually means there's a typoin your chart specification. See the javascript console for the fulltraceback.

最佳答案

看起来渲染器无法处理具有数百个条目的显式排序顺序;这可能是 Vega 中的一个错误,但它也有点反模式。

尝试做这样的事情:

alt.Chart(df.reset_index()).mark_rect().encode(
x=alt.X('time', sort=alt.SortField('index')),
color='value:Q'
)

关于Python Altair 渲染错误 - Javascript 错误 : too much recursion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66785847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com