Python 可视化

编写 Python 代码以使用示例数据直观呈现加权有向图

在对 Cloud 控制台使用不同参数值时,或通过直接调用 Vertex AI API,您可以直接查询模型,并测试返回的结果。

提示自由格式


Write Python code to draw nodes and edges of a weighted directed graph.
Each edge should be color-coded according to its weight. Add example data
to the graph to illustrate how to use the code.

                

响应


```python
import networkx as nx
import matplotlib.pyplot as plt

# Create a weighted directed graph
G = nx.DiGraph()
G.add_weighted_edges_from([
('A', 'B', 0.6),
('A', 'C', 0.2),
('B', 'D', 0.1),
('C', 'D', 0.7),
])

# Color-code the edges according to their weight
edge_colors = [plt.cm.jet(weight) for weight in nx.get_edge_attributes(G, 'weight').values()]

# Draw the graph
nx.draw(G, with_labels=True, edge_color=edge_colors)
plt.show()
```

              
型号: gemini-1.0-pro-001
温度: 0.2
输出令牌数量上限: 2048
TopK: 40
TopP: 0.95