Algorithms For Dummies



Download 7,18 Mb.
Pdf ko'rish
bet288/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   284   285   286   287   288   289   290   291   ...   651
Bog'liq
Algorithms

 

»

NetworkX (

https://networkx.github.io/



): Contains code for draw-

ing graphs.



 

»

matplotlib (

http://matplotlib.org/



): Provides access to all sorts of 

drawing routines, some of which can display graphs created by NetworkX.

To use packages in Python, you must import them. When you need to use external 

packages, you must add special code, such as the following lines of code that pro-

vide access to 

matplotlib

 and 

networkx


. (You can find this code in the 

A4D; 08; 

Draw Graph.ipynb

 file on the Dummies site as part of the downloadable code; see 

the Introduction for details.)

import networkx as nx

import matplotlib.pyplot as plt

%matplotlib inline

The special 

%matplotlib inline

 entry lets you see your plots directly in the 

Notebook rather than as an external graphic. Using this entry means that you can 

create a Notebook with graphics already included so that you don’t have to run the 

code again to see the results you received in the past.

Now that you have access to the packages, you create a graph. In this case, a graph 

is a sort of container that holds the key attributes that define the graph. Creating 

a container lets you draw the graph so that you can see it later. The following code 

creates a NetworkX 

Graph

 object.


AGraph = nx.Graph()

Adding the key attributes to 

AGraph

 comes next. You must add both nodes and 



edges using the following code.

Nodes = range(1,5)

Edges = [(1,2), (2,3), (3,4), (4,5), (1,3), (1,5)]

As previously mentioned, 

Edges

 describe connections between 



Nodes

. In this case, 

Nodes

 contains values from 1 through 5, so 



Edges

 contains connections between 

those values.



CHAPTER 8


Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   284   285   286   287   288   289   290   291   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish