Visualisasi Python

Tulis kode Python untuk memvisualisasikan grafik terarah tertimbang dengan data contoh

Anda dapat membuat kueri model secara langsung dan menguji hasil yang ditampilkan saat menggunakan parameter value yang berbeda dengan Konsol Cloud, atau dengan memanggil Vertex AI API secara langsung.

Perintah Freeform


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.

                

Respons


```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()
```

              
Model: gemini-1.0-pro-001
Suhu: 0,2
Token output maks: 2048
TopK: 40
TopP: 0,95