networkx_plot() di Sage

Dodecahedral :

sage: import networkx
sage: D = networkx.dodecahedral_graph()
sage: networkx_plot(D, pos=None, vertex_labels=True, vertex_size=200, vertex_colors=None, edge_colors=None, graph_border=False, scaling_term=0.01, draw_edges=True)

Icosahedral :

sage: import networkx
sage: D = networkx.icosahedral_graph()
sage: networkx_plot(D, pos=None, vertex_labels=True, vertex_size=200, vertex_colors=None, edge_colors=None, graph_border=False, scaling_term=0.05, draw_edges=True)

Tetrahedral :

sage: import networkx
sage: D = networkx.tetrahedral_graph()
sage: networkx_plot(D, pos=None, vertex_labels=True, vertex_size=200, vertex_colors=None, edge_colors=None, graph_border=False, scaling_term=0.05, draw_edges=True)

Octahedral :

sage: import networkx
sage: D = networkx.octahedral_graph()
sage: networkx_plot(D, pos=None, vertex_labels=True, vertex_size=200, vertex_colors=None, edge_colors=None, graph_border=False, scaling_term=0.05, draw_edges=True)

Rainbow Cube :

C = graphs.CubeGraph(7)
from sage.plot.plot import rainbow
R = rainbow(5)
edge_colors = {}
for i in range(5):
….edge_colors[R[i]] = []
for u,v,l in C.edges():
….for i in range(5):
……..if u[i] != v[i]:
………..edge_colors[R[i]].append((u,v,l))
networkx_plot(C.networkx_graph(), pos=C.get_pos(), edge_colors=edge_colors, vertex_labels=False, vertex_size=0)

Petersen Graph :

import networkx
from math import sin, cos, pi
P = networkx.petersen_graph()
d = {‘#FF0000’:[0,5], ‘#FF9900’:[1,6], ‘#FFFF00’:[2,7], ‘#00FF00’:[3,8], ‘#0000FF’:[4,9]}
pos_dict = {}
for i in range(5):
….x = float(cos(pi/2 + ((2*pi)/5)*i))
….y = float(sin(pi/2 + ((2*pi)/5)*i))
….pos_dict[i] = [x,y]

for i in range(10)[5:]:
….x = float(0.5*cos(pi/2 + ((2*pi)/5)*i))
….y = float(0.5*sin(pi/2 + ((2*pi)/5)*i))
….pos_dict[i] = [x,y]

networkx_plot(graph=P, vertex_colors=d, pos=pos_dict)

Catatan :
…… (hapus saja)

[SAGE], SAGE Mathematical Software, Version 3.2.3, http://www.sagemath.org/

Hypotrochoid

L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100), \
6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)]
….for i in range(200)]
p = polygon(L, rgbcolor=(1/2,1/4,1/8))
p.save()

L = [[6*cos(pi*i/100)+3*cos((6/2)*pi*i/100), \
6*sin(pi*i/100)-3*sin((6/2)*pi*i/100)]
….for i in range(200)]
p = polygon(L, rgbcolor=(1/2,1/4,1/8))
p.save()

L = [[5*cos(pi*i/100)+5*cos(3*pi*i/100), \
5*sin(pi*i/100)-5*sin(3*pi*i/100)]
….for i in range(200)]
p = polygon(L, rgbcolor=(1/8,1/4,1/2))
p.save()

[SAGE], SAGE Mathematical Software, Version 3.2.3, http://www.sagemath.org

Fungsi circle() di Sage, figsize dan aspect_ratio

Input untuk fungsi circle() :

center, titik pusat lingkaran, 2-tuple (x,y)
radius, jari-jari lingkaran, bilangan positif
alpha, default: 1
fill, default: False
thickness, default: 1
rgbcolor, default: (0,0,0)

Atau fungsi dasarnya : circle(center, radius, **option), dengan opsi :

alpha untuk mengukur transparansi garis
fill untuk mengisi warna
thickness untuk mengukur ketebalan garis
rgbcolor untuk mengukur warna gambar dalam 3-tuple R (red), G (green), dan B (blue) dalam nilai antara 0 dan 1.

Misal untuk membuat lingkaran hijau muda yang berpusat di titik (1,1) dan berjari-jari 2 :

sage: c = circle((1,1), 2, rgbcolor=(0.5,1,0.5), alpha=2, fill=False, thickness=2)
sage: c.show()

Hasil plotting untuk program di atas. Atau bisa pula seperti ini :

sage: show(circle((1,1), 2, rgbcolor=(0.5,1,0.5), alpha=2, fill=False, thickness=2))

Hasilnya. Bila dievaluasi ternyata lingkaran yang dihasilkan masih lonjong karena aspect ratio-nya belum dikoreksi. Untuk mengkoreksinya, yaitu dengan mengatur apect ratio gambar, diantaranya dengan menambahkan figsize berdimensi kuadrat [] di dalam fungsi show(). Misal :

sage: c = circle((1,1), 2, rgbcolor=(0.5,1,0.5), alpha=2, fill=False, thickness=2)
sage: c.show(figsize=[5,5],xmin=-1,xmax=3,ymin=-1,ymax=3)

Yang hasilnya. Di samping figsize, opsi aspect_ratio juga bisa digunakan, misal :

sage: c = circle((1,1), 2, rgbcolor=(0.5,1,0.5), alpha=2, fill=False, thickness=2)
sage: c.show(aspect_ratio=1,xmin=-1,xmax=3,ymin=-1,ymax=3)

Hasil plotting yang ke-empat.

[SAGE], SAGE Mathematical Software, Version 3.2.3, http://www.sagemath.org