### Install Debug Visualizer Python Package Source: https://gitlab.com/fehrlich/vscode-debug-visualizer-py/-/blob/main/README.md Install the vscodedebugvisualizer package within your debug environment. The Debug Visualizer extension must be installed in VSCode first. This package provides Python bindings and visualization support. ```bash pip install vscodedebugvisualizer ``` -------------------------------- ### Register Custom Visualizers with globalVisualizationFactory Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Allows users to register custom visualizers for their own data types. Requires implementing `checkType()` and `visualize()` methods. The example demonstrates visualizing a custom `Person` class as a graph. ```python from vscodedebugvisualizer import globalVisualizationFactory import json # Define a custom class class Person: def __init__(self, name, parents=None): self.name = name self.parents = [] if parents is None else parents def addParent(self, parent): self.parents.append(parent) # Create a custom visualizer class PersonVisualizer: def checkType(self, t): return isinstance(t, Person) def visualizePerson(self, person, nodes=[], edges=[]): if person.name in [n["id"] for n in nodes]: return nodes, edges nodes.append({"id": person.name, "label": person.name}) for p in person.parents: nodes, edges = self.visualizePerson(p, nodes, edges) edges.append({"from": p.name, "to": person.name}) return nodes, edges def visualize(self, person): jsonDict = { "kind": {"graph": True}, "nodes": [], "edges": [] } self.visualizePerson(person, jsonDict["nodes"], jsonDict["edges"]) return json.dumps(jsonDict) # Register the visualizer globalVisualizationFactory.addVisualizer(PersonVisualizer()) # Use it grandparent = Person("John") parent = Person("Jane", [grandparent]) child = Person("Bob", [parent]) # In debugger, inspecting 'child' will show a graph visualization from vscodedebugvisualizer import visualize result = visualize(child) # Returns: {"kind": {"graph": true}, "nodes": [{"id": "John", "label": "John"}, ...], "edges": [...]} ``` -------------------------------- ### Define Custom Class for Visualization - Python Source: https://gitlab.com/fehrlich/vscode-debug-visualizer-py/-/blob/main/README.md Create a custom Python class that will be visualized using the Debug Visualizer. This example defines a Person class with name and parent relationships that can be visualized as a graph structure. ```python class Person: def __init__(self, name, parents=None) -> None: self.name = name self.parents = [] if parents is None else parents def addParent(self, parent: "Person"): self.parents.append(parent) ``` -------------------------------- ### Custom JSON Visualization with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Allows direct control over the Debug Visualizer output by passing pre-formatted visualization dictionaries. These dictionaries must include a 'kind' key specifying the visualization type (e.g., 'graph', 'tree', 'custom'). The 'vscodedebugvisualizer' package is required. Outputs are JSON strings conforming to the Debug Visualizer specification. ```python from vscodedebugvisualizer import visualize import json # Graph visualization graph_data = { "kind": {"graph": True}, "nodes": [ {"id": "A", "label": "Node A"}, {"id": "B", "label": "Node B"}, {"id": "C", "label": "Node C"} ], "edges": [ {"from": "A", "to": "B"}, {"from": "B", "to": "C"} ] } result = visualize(graph_data) # Returns: JSON string of graph data for network visualization # Custom tree structure tree_data = { "kind": {"tree": True}, "root": { "id": "root", "children": [ {"id": "child1", "children": []}, {"id": "child2", "children": [{"id": "grandchild1", "children": []}]} ] } } result = visualize(tree_data) # Returns: JSON string formatted for tree visualization # Any custom format supported by Debug Visualizer custom_viz = { "kind": {"custom": True}, "data": [1, 2, 3, 4, 5], "options": {"color": "blue", "title": "My Custom Viz"} } result = visualize(custom_viz) ``` -------------------------------- ### Visualize Python Objects with visualize() Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt The main entry point for visualizing Python objects. It automatically detects the data type and applies the appropriate visualizer. Supports NumPy arrays, Pandas DataFrames, and primitive types, returning JSON strings with visualization configurations. ```python import numpy as np from vscodedebugvisualizer import visualize # Visualize a numpy array data = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) json_output = visualize(data) # Returns JSON string with plotly visualization including: # - Line plot of array data # - Histogram distribution # - Metadata table (shape, mean, max, min) # Visualize a pandas DataFrame import pandas as pd df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'Score': [85.5, 92.0, 78.5] }) json_output = visualize(df) # Returns JSON string with table visualization: # {"rows": [{"Name": "Alice", "Age": 25, "Score": 85.5}, ...], "kind": {"table": true}} # Visualize primitive types text_data = "Hello World" json_output = visualize(text_data) # Returns: {"kind": {"text": true}, "text": "Hello World"} ``` -------------------------------- ### Create Custom Visualizer for Person Type - Python Source: https://gitlab.com/fehrlich/vscode-debug-visualizer-py/-/blob/main/README.md Implement a custom visualizer by creating a debugvisualizer.py file in your project root. The PersonVisualizer class implements checkType() to identify Person objects and visualize() to generate graph visualization data in JSON format for the Debug Visualizer client. ```python from Person import Person from pandas.io import json from vscodedebugvisualizer import globalVisualizationFactory class PersonVisualizer: def checkType(self, t): """ checks if the given object `t` is an instance of Person """ return isinstance(t, Person) def visualizePerson(self, person: Person, nodes=[], edges=[]): if person.name in [n["id"] for n in nodes]: return nodes, edges nodes.append( { "id": person.name, "label": person.name, } ) for p in person.parents: nodes, edges = self.visualizePerson(p, nodes, edges) edges.append( { "from": p.name, "to": person.name, } ) return nodes, edges def visualize(self, person: Person): jsonDict = { "kind": {"graph": True}, "nodes": [], "edges": [], } self.visualizePerson(person, jsonDict["nodes"], jsonDict["edges"]) return json.dumps(jsonDict) globalVisualizationFactory.addVisualizer(PersonVisualizer()) ``` -------------------------------- ### List Visualization with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Visualizes Python lists intelligently based on their content. Geometric lists are displayed as maps, numeric lists as plots, and string lists as grids. Dependencies include the 'vscodedebugvisualizer' package and optionally 'numpy' and 'shapely.geometry'. Input can be a standard Python list or a list of geometric objects. ```python from vscodedebugvisualizer import visualize import numpy as np # Numeric list (converted to numpy array) numbers = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] result = visualize(numbers) # Automatically converted to numpy array and visualized as line plot # 2D numeric list matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] result = visualize(matrix) # Converted to 2D numpy array with heatmap/line visualization # String list (grid layout) text_list = ["apple", "banana", "cherry", "date"] result = visualize(text_list) # Returns: {"kind": {"grid": true}, "text": "test", "rows": [...]} # Mixed type detection from shapely.geometry import Point points = [Point(0, 0), Point(1, 1), Point(2, 2)] result = visualize(points) # Detected as shapely list, visualized as scatter plot with colored markers ``` -------------------------------- ### Primitive Type Visualization with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Visualizes basic Python primitive types such as strings, integers, floats, and dictionaries by converting them into a text-based JSON output. This functionality requires the 'vscodedebugvisualizer' package. The output is a JSON object with a 'kind' set to 'text' and the value represented as a string. ```python from vscodedebugvisualizer import visualize # String visualization text = "Debug output: Connection established" result = visualize(text) # Returns: {"kind": {"text": true}, "text": "Debug output: Connection established"} # Integer visualization count = 42 result = visualize(count) # Returns: {"kind": {"text": true}, "text": "42"} # Float visualization pi = 3.14159265359 result = visualize(pi) # Returns: {"kind": {"text": true}, "text": "3.14159265359"} # Dictionary visualization config = {"host": "localhost", "port": 8080, "debug": True} result = visualize(config) # Returns: {"kind": {"text": true}, "text": "{'host': 'localhost', 'port': 8080, 'debug': True}"} ``` -------------------------------- ### Visualize Shapely Geometries with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Visualizes Shapely geometric objects like Points, LineStrings, and Polygons as interactive Plotly scatter plots. Supports single geometries and lists of geometries with color coding. Dependencies: shapely, vscodedebugvisualizer. ```python from shapely.geometry import Point, LineString, Polygon, MultiPolygon from vscodedebugvisualizer import visualize # Point visualization point = Point(2.0, 3.0) result = visualize(point) # Creates scatter plot with single marker at (2, 3) # LineString visualization line = LineString([(0, 0), (1, 1), (2, 0), (3, 1)]) result = visualize(line) # Creates line plot connecting the coordinates # Polygon with hole exterior = [(0, 0), (4, 0), (4, 4), (0, 4)] hole = [(1, 1), (3, 1), (3, 3), (1, 3)] poly = Polygon(exterior, [hole]) result = visualize(poly) # Creates filled polygon with: # - Exterior boundary (solid line) # - Interior hole (dotted line) # - Semi-transparent fill # List of geometries (with color coding) geometries = [ Point(0, 0), Point(1, 1), LineString([(0, 0), (2, 2)]), Polygon([(3, 3), (5, 3), (5, 5), (3, 5)]) ] result = visualize(geometries) # Each geometry gets a unique color with HSL-based hue offset ``` -------------------------------- ### Visualize GeoPandas GeoDataFrames with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Visualizes GeoPandas GeoDataFrames, combining map and table views. Displays geometries in scatter plots and attributes in data tables. Supports GeoDataFrames and GeoSeries. Dependencies: geopandas, shapely, vscodedebugvisualizer. ```python import geopandas as gpd from shapely.geometry import Point, Polygon from vscodedebugvisualizer import visualize # Create GeoDataFrame with points gdf_points = gpd.GeoDataFrame({ 'City': ['New York', 'Los Angeles', 'Chicago'], 'Population': [8336817, 3979576, 2693976], 'geometry': [Point(-74.006, 40.7128), Point(-118.2437, 34.0522), Point(-87.6298, 41.8781)] }) result = visualize(gdf_points) # Creates two-panel visualization: # Top: Scatter plot of point locations # Bottom: Table with City, Population, geometry columns # GeoDataFrame with polygons gdf_poly = gpd.GeoDataFrame({ 'Region': ['Area A', 'Area B'], 'Value': [100, 200], 'geometry': [ Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]), Polygon([(1, 0), (2, 0), (2, 1), (1, 1)]) ] }) result = visualize(gdf_poly) # Top panel shows filled polygons with labels # Bottom panel shows tabular data with geometry type # GeoSeries visualization geoseries = gdf_points.geometry result = visualize(geoseries) ``` -------------------------------- ### Visualize PyTorch Tensors with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Visualizes PyTorch tensors, including CPU and GPU tensors with gradients. It automatically converts tensors to NumPy arrays for display. Dependencies: torch, vscodedebugvisualizer. ```python import torch from vscodedebugvisualizer import visualize # CPU tensor visualization tensor = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) result = visualize(tensor) # Internally calls: tensor.cpu().detach() then visualizes as numpy array # GPU tensor with gradients if torch.cuda.is_available(): gpu_tensor = torch.randn(100, 1000, requires_grad=True).cuda() result = visualize(gpu_tensor) # Automatically moved to CPU and detached before visualization # Gradient visualization x = torch.randn(5, 10, requires_grad=True) y = x.sum() y.backward() gradient = x.grad result = visualize(gradient) # Visualizes the gradient tensor as a heatmap/line plot ``` -------------------------------- ### Visualize TensorFlow Tensors with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Visualizes TensorFlow tensors by converting them to NumPy arrays. Supports constant, variable, and computed tensors from eager execution. Dependencies: tensorflow, vscodedebugvisualizer. ```python import tensorflow as tf from vscodedebugvisualizer import visualize # TensorFlow constant tensor = tf.constant([[1, 2, 3], [4, 5, 6]], dtype=tf.float32) result = visualize(tensor) # Internally calls: tensor.numpy() then visualizes as numpy array # TensorFlow variable var = tf.Variable(tf.random.normal([50, 200])) result = visualize(var) # Converts to numpy and creates plotly visualization # Eager execution tensor @tf.function def compute(): return tf.range(100) ** 2 output = compute() result = visualize(output) # Visualizes computed tensor values ``` -------------------------------- ### NumPy Array Visualization with NumpyVisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Specifically visualizes NumPy arrays using interactive Plotly charts. It generates line plots, histograms, and metadata tables. Handles multi-dimensional arrays by reducing them to 2D and downsampling if necessary, with limits on the number of visualized channels. ```python import numpy as np from vscodedebugvisualizer import visualize # 1D array visualization arr_1d = np.array([1, 4, 9, 16, 25, 36, 49, 64, 81, 100]) result = visualize(arr_1d) # Creates plot with: # - Single line showing data progression # - Histogram of value distribution # - Metadata: shape=(10,), mean=38.5, max=100, min=1 # 2D array visualization arr_2d = np.random.randn(10, 500) # 10 channels, 500 samples result = visualize(arr_2d) # Creates visualization with: # - Up to 100 line plots (one per row, limited to maxChannels=100) # - Histogram for each channel # - Metadata table # - X-axis: sample indices (0-499) # - Y-axis: array values # Multi-dimensional array (automatically reduced to 2D) arr_3d = np.random.randn(5, 10, 200) result = visualize(arr_3d) ``` -------------------------------- ### Visualize Pandas DataFrames with vscodedebugvisualizer Source: https://context7.com/fehrlich/vscode-debug-visualizer-py/llms.txt Converts Pandas DataFrames into a tabular JSON format suitable for the VS Code Debugger. Supports basic, indexed, and large DataFrames. Dependencies: pandas, vscodedebugvisualizer. ```python import pandas as pd from vscodedebugvisualizer import visualize import numpy as np # Basic DataFrame df = pd.DataFrame({ 'Product': ['Apple', 'Banana', 'Orange'], 'Price': [1.20, 0.50, 0.80], 'Quantity': [100, 150, 120] }) result = visualize(df) # Returns: {"rows": [{"Product": "Apple", "Price": 1.2, "Quantity": 100}, ...], "kind": {"table": true}} # DataFrame with index df_indexed = pd.DataFrame({ 'Temperature': [72, 75, 68, 80], 'Humidity': [45, 50, 42, 55] }, index=['Monday', 'Tuesday', 'Wednesday', 'Thursday']) result = visualize(df_indexed) # Index becomes part of row data # Large DataFrame (all rows included) large_df = pd.DataFrame(np.random.randn(1000, 5), columns=list('ABCDE')) result = visualize(large_df) # Converts all 1000 rows to JSON format ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.