Grafiklar. Matplotlib moduli



Download 0,55 Mb.
Sana20.12.2022
Hajmi0,55 Mb.
#891449
Bog'liq
MatPlotLib

Grafiklar. Matplotlib moduli

Matplotlib da graphika

  • import matplotlib.pyplot as plt
  • plt.plot([1, 2, 3, 4, 5], [1, 2, 3, 4, 5])
  • plt.show()
  • import numpy as np
  • # Независимая (x) и зависимая (y) переменные
  • x = np.linspace(0, 10, 50)
  • y = x
  • # Построение графика
  • plt.title("Линейная зависимость y = x") # заголовок
  • plt.xlabel("x") # ось абсцисс
  • plt.ylabel("y") # ось ординат
  • plt.grid() # включение отображение сетки
  • plt.plot(x, y) # построение графика

y = f(x) кўринишли функцияларнинг графигини чизиш

  • Ушбу графикни ҳосил қилиш учун Python да қуйидаги кўринишли код ёзамиз:
  • import matplotlib.pyplot as plt
  • import numpy as np
  • # Prepare the
  • datax = np.linspace(0, 10, 100)
  • # Plot the
  • dataplt.plot(x, x, label='linear')
  • # Add a l
  • egendplt.legend()
  • # Show the
  • plotplt.show()

import matplotlib.pyplot as plt

# x axis values

x = [1,2,3]

# corresponding y axis values

y = [2,4,1]

# plotting the points

plt.plot(x, y)

# naming the x axis

plt.xlabel('x - axis')

# naming the y axis

plt.ylabel('y - axis')

# giving a title to my graph

plt.title('My first graph!')

# function to show the plot

plt.show()

import matplotlib.pyplot as plt

  • import matplotlib.pyplot as plt
  • # line 1 points
  • x1 = [1,2,3]
  • y1 = [2,4,1]
  • # plotting the line 1 points
  • plt.plot(x1, y1, label = "line 1")
  • # line 2 points
  • x2 = [1,2,3]
  • y2 = [4,1,3]
  • plt.plot(x2, y2, label = "line 2") # plotting the line 2 points
  • plt.xlabel('x - axis') # naming the x axis
  • plt.ylabel('y - axis') # naming the y axis
  • plt.title('Two lines on same graph!') # giving a title to my graph
  • plt.legend() # show a legend on the plot
  • plt.show() # function to show the plot

import matplotlib.pyplot as plt

  • import matplotlib.pyplot as plt
  • # x axis values
  • x = [1,2,3,4,5,6]
  • # corresponding y axis values
  • y = [2,4,1,5,2,6]
  • # plotting the points
  • plt.plot(x, y, color='green', line, linewidth = 3, marker='o', markerfacecolor='blue', markersize=12)
  • # setting x and y axis range
  • plt.ylim(1,8)
  • plt.xlim(1,8)
  • plt.xlabel('x - axis') # naming the x axis
  • plt.ylabel('y - axis') # naming the y axis
  • plt.title('Some cool customizations!') # giving a title to my graph
  • plt.show() # function to show the plot

Гистограмма

  • import matplotlib.pyplot as plt
  • # x-coordinates of left sides of bars
  • left = [1, 2, 3, 4, 5]
  • height = [10, 24, 36, 40, 5] # heights of bars
  • tick_label = ['one', 'two', 'three', 'four', 'five'] # labels for bars
  • # plotting a bar chart
  • plt.bar(left, height, tick_label = tick_label, width = 0.8, color = ['red', 'green'])
  • plt.xlabel('x - axis') # naming the x-axis
  • plt.ylabel('y - axis') # naming the y-axis
  • plt.title('My bar chart!') # plot title
  • plt.show() # function to show the plot

Круговая диаграмма

  • import matplotlib.pyplot as plt
  • # defining labels
  • activities = ['eat', 'sleep', 'work', 'play']
  • # portion covered by each label
  • slices = [3, 7, 8, 6]
  • colors = ['r', 'y', 'g', 'b'] # color for each label
  • # plotting the pie chart
  • plt.pie(slices, labels = activities, colors=colors, startangle=90, shadow = True, explode = (0, 0, 0.1, 0),
  • radius = 1.2, autopct = '%1.1f%%')
  • plt.legend() # plotting legend
  • plt.show() # showing the plot
  • # importing the required modules
  • import matplotlib.pyplot as plt
  • import numpy as np
  • # setting the x - coordinates
  • x = np.arange(0, 2*(np.pi), 0.1)
  • # setting the corresponding y - coordinates
  • y = np.sin(x)
  • plt.plot(x, y) # plotting the points
  • plt.show() # function to show the plot
  • import numpy as np
  • import matplotlib.pyplot as plt
  • X = np.linspace(-np.pi, np.pi, 256)
  • C, S = np.cos(X), np.sin(X)
  • plt.plot(X, C)
  • plt.plot(X, S)
  • plt.show()

3D Plots

  • from mpl_toolkits.mplot3d import Axes3D
  • fig = plt.figure()
  • ax = Axes3D(fig)
  • X = np.arange(-4, 4, 0.25)
  • Y = np.arange(-4, 4, 0.25)
  • X, Y = np.meshgrid(X, Y)
  • R = np.sqrt(X**2 + Y**2)
  • Z = np.sin(R)
  • ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')

Download 0,55 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
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