plotting.py


Overview

The `plotting.py` file provides visualization utilities designed to analyze and display relationships between **code embeddings** and **documentation embeddings** in a software project. Its primary focus is on semantic coverage and similarity metrics between code and associated documentation units.

There are two main visualization functions:

Both functions leverage Plotly for interactive visualization and allow saving the plots as HTML files.


Detailed Documentation

Imports and Constants


Function: plotly_radar_and_bar

def plotly_radar_and_bar(results_ces: Dict, code_embeddings: List[np.ndarray], doc_embeddings: List[np.ndarray],
                         out_path: Optional[str] = None)

Purpose

Visualizes summary metrics and coverage distribution of code units against documentation using:

Parameters

Returns

Usage Example

results = {"DirectCoverage": 0.75, "Relevance": 0.65, "Novelty": 0.40}
plotly_radar_and_bar(results, code_embeddings, doc_embeddings, out_path="coverage.html")

Implementation Details


Function: plot_semantic_scatter

def plot_semantic_scatter(code_embeddings: List[np.ndarray],
                          doc_embeddings: List[np.ndarray],
                          code_units: List[str],
                          doc_units: List[str],
                          out_path: Optional[str] = None,
                          use_umap: bool = False)

Purpose

Creates an interactive 2D scatter plot visualizing semantic relationships between code and documentation units in a shared embedding space.

Parameters

Returns

Usage Example

plot_semantic_scatter(code_embeddings, doc_embeddings, code_names, doc_names, out_path="semantic_map.html")

Implementation Details


Key Algorithms and Concepts


Interactions with Other Modules

These connections enable the plotting functions to integrate seamlessly into a larger analysis pipeline that generates embeddings, computes metrics, and visualizes results.


Mermaid Diagram: Function Flowchart for plotting.py

flowchart TD
    A[plotly_radar_and_bar] --> B[Calculate coverage counts]
    B --> C[Create radar chart for CES metrics]
    B --> D[Create bar chart for coverage counts]
    C & D --> E[Display or save plot]

    F[plot_semantic_scatter] --> G[Combine embeddings]
    G --> H{Use UMAP?}
    H -- Yes --> I[Apply UMAP]
    H -- No --> J[Apply t-SNE]
    I & J --> K[Split reduced coords]
    K --> L[Plot code units scatter]
    K --> M[Plot doc units scatter]
    L & M --> N[Draw similarity lines]
    N --> O[Compute convex hull on covered code units]
    O --> P[Add hull polygon]
    P --> Q[Display or save plot]

Summary

`plotting.py` is a specialized visualization utility focused on semantic coverage and relationships between code and documentation embeddings. It provides interactive, insightful visualizations using advanced dimensionality reduction and similarity metrics, aiding developers and analysts in understanding and improving documentation coverage and relevance.


**End of documentation for `plotting.py`.**