Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Escribe código de Python para visualizar un grafo dirigido ponderado con datos de ejemplo
Puedes buscar un modelo directamente y probar los resultados que se muestran cuando usas valores de parámetros diferentes con la consola de Cloud o con una llamada directa a la API de Vertex AI.
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.
Respuesta
```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()
```
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","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"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2024-04-18 (UTC)"],[],[]]