Reprezintă grafic numărul de modificări ale muchiilor în timp
Acum vei crea câteva grafice! Toate listele pe care le-ai creat anterior au fost încărcate pentru tine și în acest exercițiu. Nu te îngrijora de codul matplotlib mai elaborat care apare mai jos: există comentarii care te ajută să înțelegi ce se întâmplă.
Acest exercițiu face parte din cursul
Analiză intermediară a rețelelor în Python
Instrucțiuni pentru exercițiu
- Reprezintă grafic numărul de muchii adăugate în timp. Pentru a face asta:
- Folosește o expresie de tip list comprehension pentru a itera peste
addedși creează o listă numităedges_added. Expresia de ieșire a list comprehension-ului estelen(g.edges()), undegeste variabila ta de iterare. - Pasează lista
edges_addedlaax1.plot().
- Folosește o expresie de tip list comprehension pentru a itera peste
- Reprezintă grafic numărul de muchii eliminate în timp. Din nou, folosește o expresie de tip list comprehension, de data aceasta iterând peste
removedîn loc deadded. - Reprezintă grafic modificările fracționale în timp, pasându-le ca argument la
ax2.plot().
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
# Import matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
# Plot the number of edges added over time
edges_added = [____(____) for ____ in ____]
plot1 = ax1.plot(____, label='added', color='orange')
# Plot the number of edges removed over time
edges_removed = [____(____) for ____ in ____]
plot2 = ax1.plot(____, label='removed', color='purple')
# Set yscale to logarithmic scale
ax1.set_yscale('log')
ax1.legend()
# 2nd axes shares x-axis with 1st axes object
ax2 = ax1.twinx()
# Plot the fractional changes over time
plot3 = ax2.plot(____, label='fractional change', color='green')
# Here, we create a single legend for both plots
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(lines1 + lines2, labels1 + labels2, loc=0)
plt.axhline(0, color='green', linestyle='--')
plt.show()