Python'da Çizimleri Canlandırmak
Bu yazıda, görselleştirmelerinize hoş bir dokunuş katabilmeniz için Matplotlib kullanarak Python'da çizimleri nasıl canlandıracağınızı göstereceğim !
Matplotlib
Matplotlib, Python programlama dili için bir çizim paketidir. Python'daki görselleştirmeler için en popüler paketlerden biridir ve kullanıcılara 2 boyutlu, 3 boyutlu ve hatta animasyonlu çizimler oluşturma yeteneği sağlar. Matplotlib, çizgi grafikleri, dağılım grafikleri, çubuk grafikler ve histogramlar dahil olmak üzere grafikler oluşturmak için bir dizi özelleştirilebilir seçenek sunar. Birçok kişi, statik görselleştirmeler için Matplotlib'i kullanmaya zaten aşina olduğundan, animasyonlu grafikler için kullanımını ele alacağım. Matplotlib'de yeni olan ancak Python'a zaten aşina olanlar için pakete başlamanız için harika bir kaynak.
Temel 2-D Animasyonlu Arsa
#Empty lists for X/Y data
x = []
y = []
#Create a figure and axis to plot on
fig, ax = plt.subplots()
#We will create a function that will be called by Matplotlib's FuncAnimation
def getAnimation(iterator):
newInt = random.randint(1,10)
#Append values to our lists
x.append(iterator)
y.append(newInt)
#Clear previous data from the plot
ax.clear()
#Plot the lists with axis limits
ax.plot(x, y)
ax.set_xlim([0,20])
ax.set_ylim([0,20])
#We pass FuncAnimation our getAnimation function so that it is called in a loop
animation = FuncAnimation(fig, getAnimation, frames=20,
interval=500, repeat=False)
plt.show()
Matplotlib aracılığıyla sağlanan FuncAnimation(), belirli sayıda çerçeve içeren bir döngüde çalışacak bir şekil ve işlev gerektirir. getAnimation() öğesini bir bağımsız değişken olarak ileterek , temelde bir animasyon oluşturmak için bir araya gelen ve kare sayısı kadar döngü yapan grafiklerden oluşan bir slayt gösterisi oluşturuyoruz . Bu bizim kodumuzun sonucudur…
Rastgele Bir 3 Boyutlu Yürüme Animasyonu
#Empty lists for X/Y/Z data
x = []
y = []
z = []
#Lets start off at (10,10,10) the center of our figure with axis limits 20
x.append(10)
y.append(10)
z.append(10)
#Total number of steps we will take
stepTotal = 20
#Create a figure and axis to plot on (3-D)
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
#We will create a function that will be called by Matplotlib's FuncAnimation
def randomWalk(step):
#Append values to our lists
x.append(random.uniform(1,10))
y.append(random.uniform(1,10))
z.append(random.uniform(1,10))
#Clear previous data from the plot
ax.clear()
#Plot the lists with axis limits
ax.plot(x, y, z)
ax.set_xlim([0,20])
ax.set_ylim([0,20])
ax.set_zlim([0,20])
# Creating the Animation object
animation = FuncAnimation(fig, randomWalk, frames=stepTotal, interval=100)
plt.show()
Animasyonları Kaydetme
#FuncAnimation() returns an animation object that can be stored
animation = FuncAnimation()
#Instantiate the directory you wish to save to
directory = "/medium/animation.gif"
#We call .save() on our animation object and pass the function a directory
animation.save(directory)
Bu makaledeki tüm kodlar benim Github'umda bulunabilir .
Bu Medium makalesini ilginç bulduysanız, beni takip etmeyi düşünün! Matematik, Bilgisayar Bilimi ve aradaki her şey hakkında yazıyorum!

![Bağlantılı Liste Nedir? [Bölüm 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)



































