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

如何在Orange3工作流中实现个性化绘图及直接展示脚本输出?

Answers to Your Orange3 Visualization Questions

Hey Martin, let’s tackle your two questions with practical, actionable solutions—Orange3 has some flexible tools for custom visualization once you know where to look!

1. How to Visualize Custom Charts in an Orange3 Workflow?

The most straightforward way to build personalized visualizations is combining the Python Script widget with Orange’s built-in viewers. Here’s a step-by-step breakdown:

  • Step 1: Generate your custom plot in the Python Script widget
    Drag a Python Script widget into your workflow, connect your input data source to it, then write your custom matplotlib code. Be sure to output the figure object so Orange can pass it to a viewer. Example code:

    import matplotlib.pyplot as plt
    from Orange.data import Table
    
    # Grab input data (connect your data source to the widget's input first)
    data = in_data
    
    # Create your tailored plot
    fig, ax = plt.subplots(figsize=(8, 6))
    ax.scatter(data.X[:, 0], data.X[:, 1], c=data.Y, cmap="viridis")
    ax.set_title("Custom Scatter Plot with Class Coloring")
    ax.set_xlabel(data.domain[0].name)
    ax.set_ylabel(data.domain[1].name)
    
    # Output the figure to send to a viewer
    out_figure = fig
    
  • Step 2: Display the plot with the Image Viewer widget
    Drag an Image Viewer widget into your workflow, connect the out_figure port from the Python Script widget to the Image Viewer’s input. Your custom chart will render automatically.

    For interactive plots (with zoom/pan functionality), you can also use the Interactive Plot widget—just convert your matplotlib figure to a Plotly figure using plotly.tools.mpl_to_plotly() and output that instead.

2. Can Orange Directly Display JS or Matplotlib Output from Workflow Python Scripts?

Absolutely—here’s how to handle both cases seamlessly:

Matplotlib Output

As shown in the first question, you can directly output matplotlib figures from the Python Script widget and display them via the Image Viewer or Interactive Plot (for interactivity). This is the most native way to show matplotlib visuals in Orange.

JavaScript-Based Output (e.g., Plotly, D3.js)

To display JS-driven interactive charts, pair the Python Script widget with the Web View widget:

  • Example with Plotly (JS-powered):

    import plotly.express as px
    from Orange.data import Table
    
    data = in_data
    
    # Create an interactive Plotly chart (uses JavaScript under the hood)
    fig = px.box(
        data,
        x=data.domain.class_var.name,
        y=data.domain[0].name,
        title="Interactive JS Box Plot"
    )
    
    # Convert the Plotly figure to an HTML string
    html_output = fig.to_html(full_html=False)
    
    # Output the HTML to pass to the Web View widget
    out_html = html_output
    

    Connect the out_html port from the Python Script widget to the Web View’s input—your JS-driven chart will load directly in Orange’s interface.

  • For custom pure JS/D3.js:
    Wrap your JS/D3 code in an HTML template string in the Python Script widget, then output that string to the Web View. Example snippet:

    custom_html = """
    <html>
      <head>
        <script src="https://d3js.org/d3.v7.min.js"></script>
      </head>
      <body>
        <div id="chart" style="width: 400px; height: 300px;"></div>
        <script>
          // Custom D3.js bar chart example
          const data = [10, 20, 30, 40, 50];
          const svg = d3.select("#chart")
                        .append("svg")
                        .attr("width", 400)
                        .attr("height", 300);
          
          svg.selectAll("rect")
             .data(data)
             .enter()
             .append("rect")
             .attr("x", (d, i) => i * 70)
             .attr("y", d => 300 - d * 5)
             .attr("width", 60)
             .attr("height", d => d * 5)
             .attr("fill", "#e74c3c");
        </script>
      </body>
    </html>
    """
    out_html = custom_html
    

    The Web View widget will render the HTML and execute the embedded JavaScript code.


内容的提问来源于stack exchange,提问作者Martin Becuwe

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 06:47:36