Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
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.
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()
```
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2024-04-11 UTC."],[],[]]