【发布时间】:2021-08-30 17:26:19
【问题描述】:
我正在使用 Altair 选择图形的边缘。这个想法是选择一个或多个节点并绘制到达或离开该节点的所有边。我在https://altair-viz.github.io/gallery/airport_connections.html 的机场连接示例之后对下面的代码(最小工作示例)进行了建模。但是,当我运行我的代码时,仅显示从所选节点发出的边,而不是所有边。我将如何修改我的代码来解决这个问题。感谢您提供的任何见解。戈登。
代码和文件位于:https://drive.google.com/drive/folders/1rqQdrLAsATSqjWYCvf372SDVt5hTlC9s?usp=sharing
import pandas as pd
import altair as alt
import streamlit as st
def drawPlot(node_df, edge_df):
node_brush = alt.selection_interval(empty='all')
xscale = alt.Scale(domain=[0, 127])
yscale = alt.Scale(domain=[0.,410])
lookup_data = alt.LookupData(
node_df, key="id", fields=["x", "y"]
)
nodes = alt.Chart(node_df).mark_rect(
width=20, height=20,
).encode(
x = alt.X('x:Q', scale=xscale),
y = 'y:Q',
).add_selection(
node_brush
)
edges = alt.Chart(edge_df).mark_rule(color='yellow',
).encode(
x = alt.X('x:Q', scale=xscale),
y = 'y:Q',
x2 = 'x2:Q',
y2 = 'y2:Q',
).transform_lookup(
lookup='dst',
from_=lookup_data
).transform_lookup(
lookup='src',
from_=lookup_data,
as_=['x2', 'y2']
).transform_filter(
node_brush
)
full_chart = (edges + nodes).properties(
height=500,
width=1000,
)
#----------------------------------------------------------------
if __name__ == "__main__":
node_df = pd.read_csv("node_df_MWE.csv")
edge_df = pd.read_csv("edge_df_MWE.csv")
chart = drawPlot(node_df, edge_df)
st.altair_chart(chart, use_container_width=True)
【问题讨论】:
-
您能否提供一个包含数据的完全可重现的示例,以便我们尝试找出答案?
-
我已通过 Google Drive 上的共享链接提供了我的数据和代码。
标签: python selection altair brush