mcpField
P
pygraphistry-visualization

pygraphistry-visualization

github.com/graphistry数据与数据库341 次安装1 天前更新
代码仓库

关于 pygraphistry-visualization

pygraphistry-visualization 是面向 PyGraphistry 用户的图可视化技能,涵盖图编码、布局、交互显示与分享设置,并提供按需切分子图的工作流。

主要功能

  1. 01节点与边的颜色、大小及图标编码
  2. 02调整布局与渲染参数
  3. 03配置标签、悬停高亮和界面面板
  4. 04生成聚焦的 GFQL 子图视图
  5. 05设置图表分享隐私级别

适用场景

  1. 01按类别或数值呈现图属性
  2. 02为外部坐标图固定布局
  3. 03调查大型图中的特定子图
  4. 04控制共享图表的可见范围

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/graphistry/graphistry-skills --skill pygraphistry-visualization

安装后在 Claude Code 中输入/pygraphistry-visualization确认已加载。

附带文件references/fa-icons.md

详细介绍

PyGraphistry 可视化

文档路由(本地 + 规范链接)

  • 首先通过 ../pygraphistry/references/pygraphistry-readthedocs-toc.md 路由。
  • 使用 ../pygraphistry/references/pygraphistry-readthedocs-top-level.tsv 查找章节级快捷入口。
  • 仅在所需页面缺失时,才扫描 ../pygraphistry/references/pygraphistry-readthedocs-sitemap.xml。
  • 深入读取页面前,先进行一次批量发现读取;避免使用 cat * 和串行的微小读取。
  • 使用本地的图标查找说明 references/fa-icons.md。
  • 面向用户的回答中,优先使用规范的 https://pygraphistry.readthedocs.io/en/latest/... 链接。

核心模式

g2 = (
    # Keep a plain 'type' column on both nodes and edges for legend-friendly defaults
    g.bind(point_label='label', point_color='type', edge_color='type')
     .encode_point_color('type', categorical_mapping={'agent': '#3b82f6'}, default_mapping='#94a3b8')
     # Optional: default node sizing is often degree for exploratory passes
     .encode_point_size('degree')
     .settings(url_params={'play': 3000, 'info': True})
)
g2.plot()

外部布局模式

# nodes_df contains x/y layout columns
g2 = graphistry.edges(edges_df, 'src', 'dst').nodes(nodes_df, 'id').bind(point_x='x', point_y='y').settings(url_params={'play': 0})
g2.plot()

URL 参数参考

使用 settings(url_params={...}) 控制可视化行为。完整参考:https://hub.graphistry.com/docs/api/1/rest/url/#urloptions

布局
参数类型默认值范围描述
playint50000-10000 (0, 1000, 2000, 5000)布局时长(毫秒)。0 = 固定
lockedXboolfalse锁定 X 轴(配合 bind(point_x=...) 使用)
lockedYboolfalse锁定 Y 轴(配合 bind(point_y=...) 使用)
lockedRboolfalse锁定径向位置
linLogboolfalse强力分离;适用于少于 1000 个节点
scalingRatiofloat1.00.1-10 (0.5, 1, 2, 5)扩展比例。与 linLog 结合使用
strongGravityboolfalse紧凑布局,将节点拉向中心
dissuadeHubsboolfalse降低枢纽节点对布局的主导影响
gravityfloat1.00.1-10 (0.1, 1, 2, 10)向中心的拉力
edgeInfluencefloat1.00-10 (0, 0.7, 1, 2, 5, 7)边权重对布局的影响
precisionVsSpeedfloat1.00.1-10 (0.1, 1, 10)值越高越精确,但速度越慢
left/right/top/bottomintauto加载时手动设置摄像机边界
场景 / 渲染
参数类型默认值范围描述
pointSizefloat1.00.1-10 (0.3, 0.5, 1, 2, 3)点大小倍数(非编码值)
pointOpacityfloat1.00-1 (0.3, 0.5, 0.8, 1)节点透明度
pointStrokeWidthfloat00-5 (0, 1, 2)节点边框宽度
edgeCurvaturefloat00-1 (0, 0.5, 1)边的弯曲程度
edgeOpacityfloat1.00-1 (0.3, 0.5, 0.8, 1)边的透明度
showArrowsbooltrue显示边的方向箭头
neighborhoodHighlightstrbothincoming/outgoing/both/node悬停高亮模式
neighborhoodHighlightHopsint11-5 (1, 2, 3)悬停高亮的跳数
标签 / 兴趣点
参数类型默认值范围描述
showLabelsbooltrue切换所有标签的可见性
showLabelOnHoverbooltrue仅在悬停时显示标签
showPointsOfInterestbooltrue将关键节点标记为兴趣点(POI)
showPointsOfInterestLabelbooltrue显示兴趣点节点的标签
pointsOfInterestMaxint50-100 (0, 5, 10, 20)兴趣点上限。0 = 禁用
shortenLabelsbooltrue截断较长的标签
showLabelPropertiesOnHoverboolfalse悬停时显示额外属性
labelOpacityfloat1.00-1 (0.5, 0.8, 1)标签透明度
labelColorstrhex no # (000000, FFFFFF)标签文字颜色
labelBackgroundstrhex no # (000000, FFFFFF)标签背景颜色

注意:URL 参数使用不带 # 的十六进制值。Python API(encode_*、palette)使用带 # 前缀的值。

UI 控件
参数类型默认值描述
menubooltrue显示所有菜单
infobooltrue显示图大小统计信息
showHistogramsbooltrue显示直方图面板
showInspectorbooltrue显示实体检查器
showCollectionsboolfalse显示集合面板
示例
# Ring layout with strong separation for small graphs (<1000 nodes)
g2 = g.settings(url_params={'play': 3000, 'linLog': True, 'scalingRatio': 2.0})

# Fixed position layout (external coordinates)
g2 = g.bind(point_x='x', point_y='y').settings(url_params={'play': 0, 'lockedX': True, 'lockedY': True})

# Disable POI labels entirely
g2 = g.settings(url_params={'showLabels': False, 'pointsOfInterestMax': 0})

# Larger points, more transparent edges
g2 = g.settings(url_params={'pointSize': 3.0, 'edgeOpacity': 0.3})

# Minimal UI for embedding
g2 = g.settings(url_params={'menu': False, 'info': False, 'showHistograms': False, 'showInspector': False})

图标/徽章模式

g2 = (
    g.encode_point_icon('type', categorical_mapping={'person': 'user', 'org': 'building'})
     .encode_point_badge('risk', categorical_mapping={'high': 'exclamation-triangle'})
)
g2.plot()

使用有效的 Font Awesome 名称,并根据 type 对图标进行分类映射。 查阅 references/fa-icons.md,获取查询链接和示例。

连续色模式(超越分类映射)

g2 = g.encode_edge_color('amount', palette=['#46327e', '#1fa187', '#fde724'], as_continuous=True)
g2.plot()

聚焦子图视图(类似集合的工作流)

# Use GFQL slices to publish multiple focused views from one base graph (use .gfql(), not deprecated .chain())
high_risk = g.gfql([...]).name('high-risk-slice')
partner_flow = g.gfql([...]).name('partner-flow-slice')
urls = [high_risk.plot(render=False), partner_flow.plot(render=False)]

隐私安全的分享模式

graphistry.privacy(mode='private')
plot_url = g.plot(render=False)
  • 分享链接前,使用明确的 graphistry.privacy(mode='private'|'organization'|'public')。
  • 不要将 plot() 的参数(如 as_files 或 memoize)视为隐私控制项。

常见任务

  • 编码:encode_point_color、encode_edge_color、encode_point_size、encode_point_icon、encode_point_badge。
  • 布局:运行时力导向布局设置、环形/GIB/模块度布局、graphviz/igraph/cugraph 插件布局。
  • 静态输出:使用 plot_static() 生成 SVG/PNG,以及 graphviz-dot/mermaid-code 等文本引擎。
  • 分享控制:graphistry.privacy(mode='private'|'organization'|'public')。
  • 若要使用高级渐变,请在 encode_point_color/encode_edge_color 中使用 palette=[...] 和 as_continuous=True。
  • 对于大型调查,请生成多个聚焦的 GFQL 切片,而不是生成一个负载过重的绘图。

大型图的默认做法

  • 绘图前先进行筛选和聚合。
  • 仅保留必要的列(除非需要,否则删除大型文本块)。
  • 使用聚焦子图(时间切片、单跳邻域、top-k 信号)。
  • 节点和边都优先使用普通的 type 列,以保持图例和默认分类编码稳定。
  • 避免使用 node.type / edge.type 等带点号的列名;优先使用普通名称。
  • 时间编码和分时段比较应使用原生 datetime 类型。

权威文档

评论

支持 Markdown