You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过IronPython实现基于数据表变量的自定义表达式曲线绘制?

使用IronPython在散点图中添加“Curve from Data Table”曲线

以下是直接实现该操作的IronPython代码示例及关键说明:

核心代码实现

# 1. 定位目标散点图(按标题筛选,替换为你的散点图标题)
target_scatter = None
for visual in Application.Document.ActivePageReference.Visuals:
    if visual.Title == "我的散点图" and visual.TypeId == "ScatterPlot":
        target_scatter = visual
        break

if not target_scatter:
    raise Exception("未找到指定的散点图可视化")

# 2. 获取要引用的数据表(替换为你的数据表名称)
source_table = Application.Document.Data.Tables["数据源表"]

# 3. 指定曲线关联的X/Y列(替换为实际列名)
x_col = source_table.Columns["X轴列"]
y_col = source_table.Columns["Y轴列"]

# 4. 构建数据驱动曲线的表达式
curve_expr = f"{{X: {x_col.Name}, Y: {y_col.Name}}}"
# 如需添加过滤条件,可扩展表达式:
# curve_expr = f"{{X: {x_col.Name}, Y: {y_col.Name}, Where: [分组列] = '指定值'}}"

# 5. 添加自定义曲线到散点图
plot_config = target_scatter.As[Visualization.TypeIds.ScatterPlot]().PlottingSettings
custom_curve = plot_config.Curves.AddCustomCurve()
custom_curve.Expression = curve_expr
custom_curve.Title = "数据表驱动曲线"  # 设置曲线显示标题
custom_curve.Visible = True

# 6. 刷新可视化使曲线生效
target_scatter.Refresh()

关键说明

  • 定位可视化:通过遍历当前页面的可视化元素,结合标题和类型ID精准找到目标散点图
  • 数据源关联:直接引用数据表中的列,确保曲线与原始数据实时联动
  • 表达式扩展:支持添加过滤条件,实现仅展示符合特定规则的数据点曲线
  • 属性配置:可自定义曲线标题、可见性等展示属性

内容的提问来源于stack exchange,提问作者Zegher V

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 14:32:05