python - 在交互栏 + 热图中选择大型数据集时冻结
问题描述
按照教程https://altair-viz.github.io/gallery/interactive_cross_highlight.html
当我做我自己的数据时,即使有一些调整,这大部分都可以正常工作。但是我现在有一个奇怪的情况。
当我有任何单个条的大小超过 10,000 时,选择它(单个或多选的一部分)Altair 会冻结。没有浏览器崩溃,没有挂起,它只是停止做任何事情。
目前,我将数据读取到 pandas DF 并将其传递。我试图直接传递 CSV,但由于某种原因,我根本没有得到任何数据,只是空图表。但是,我并不完全相信 DF 是问题所在,因为它可以很好地生成初始图。只有在选择单个大条时才会出现问题。
谢谢!
编辑 :
当前尝试 -
dh = "C:\\Path\\My.csv"
outputDH='C:\\Path\\My.html'
dh_table = pd.read_csv(dh)
selector4 = alt.selection_multi(encodings=['y', 'color'])
bar4=alt.Chart(dh_table).mark_bar().encode(
x=alt.X('count():Q', axis=alt.Axis(title='Observation Count')),
y=alt.Y('rid:N', stack='zero', axis=alt.Axis(title='RIDs')),
color=alt.condition(selector4, 'int_source:N', alt.value('lightgray'),
legend=alt.Legend(title='Int Source'))
).add_selection(
selector4
)
text4 = alt.Chart(dh_table).mark_text(dx=-6, dy=3,
color='white',clip=True).encode(
x=alt.X('count(rid):Q', stack='zero'),
y=alt.Y('rid:N'),
detail='int_source:N',
text=alt.Text('count(rid):Q', format='.0f')
)
rect4 = alt.Chart(dh_table).mark_rect().encode(
alt.X('did:N', axis=alt.Axis(title='DID')),
alt.Y('directive_state:N', axis=alt.Axis(title='State')),
alt.Color('count()',
scale=alt.Scale(scheme='blues'),
legend=alt.Legend(title='Num Records')
)
)
circ4 = rect4.mark_point().encode(
alt.Color("d_enum:N",
scale=alt.Scale(scheme='inferno'),
legend=alt.Legend(title='DEnum', tickMinStep=1)
),
alt.Size('d_enum:N',
legend=alt.Legend(title='DEnum', tickMinStep=1)
)
).transform_filter(selector4)
alt.hconcat(
(rect4+circ4).resolve_scale(color='independent'),
(bar4+text4)
).resolve_legend(
color="independent",
size="independent"
).save(outputDH)
现在,当我说我尝试直接传递 CSV 时,我的意思是我没有传递数据帧 dh_table,而是传递了 dh。这导致表中没有数据。所以我回去传递数据框。
不过,我解决了。似乎它与实际为 NULL 的列有关。出于某种原因,一旦我用无意义的 ID(例如 9999999999)替换了 NULL,整个问题就消失了。它仍然需要比正常时间长一两秒,但我认为多选中有 25,000 多个条目是预期的。
解决方案
推荐阅读
- ansible - 使用 delegate_to 的 Ansible 角色依赖和事实
- openssl - 使用 Signtool 验证文件签名不起作用
- wiremock - 具有多个允许键但响应相同的 JSON 有效负载的 Wiremock 请求模板
- jmeter - JMeterLibException:'JMeter 返回的值:1'
- xamarin - 在 Xamarin 的 ViewModel 中设置 Picker 的初始值
- javascript - 反应应用程序不保存到firebase数据库
- logstash - LogStash 翻译过滤器被忽略
- python - TensorFlow:使用@tf.function 的正确方法
- java - 启用 Show In > System Explorer 的条件是什么?
- rabbitmq - 在 RabbitMQ 2.3.6 中从消息队列中侦听消息时更改了数据类型