Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Завдання 1
- import numpy as np
- import matplotlib.pyplot as plt
- x = np.linspace(0, 5, 500)
- y = -5 * np.cos(10 * x) * np.sin(3 * x) / (x**x)
- plt.plot(x, y, color='#c8f04f', linestyle='-', linewidth=3, label='-5*cos(10*x)*sin(3*x)/(x^x)')
- plt.legend(loc='lower right')
- plt.xlabel('x') # позначення вісі абсцис
- plt.ylabel('y') # позначення е вісі ординат
- plt.title('My first normal plot') # назва графіка
- plt.show()
- №Завдання 2
- import csv
- import numpy as np
- import matplotlib.pyplot as plt
- def f(datafile_name: str, _country_name: str, start_years: int, end_years: int):
- with open(datafile_name, newline='') as csvfile:
- reader = csv.DictReader(csvfile)
- tmp_y = np.array([], float)
- for row in reader:
- for i in range(start_years, end_years+1):
- s = str(i) + ' [YR' + str(i) + ']'
- if row['Country Name'] == _country_name:
- try:
- tmp_y = np.append(tmp_y, float(row[s]))
- except ValueError:
- tmp_y = np.append(tmp_y, 0)
- return tmp_y
- y_ukr = f('Data.csv', 'Ukraine', 2002, 2020)
- y_can = f('Data.csv', 'Canada', 2002, 2020)
- x = np.arange(2002, 2021, 1)
- fig1 = plt.figure()
- ax1 = fig1.add_subplot()
- ax1.plot(x, y_can, color='g', linestyle='-', linewidth=3, label='Canada')
- ax1.plot(x, y_ukr, color='r', linestyle='-', linewidth=3, label='Ukraine')
- ax1.legend(loc='lower right')
- ax1.set_xlabel('Years') # позначення вісі абсцис
- ax1.set_ylabel('Life expectancy') # позначення е вісі ординат
- ax1.set_title('Life expectancy at birth, total (years)') # назва графіка
- country_name = input("Enter name of country: ")
- fig2 = plt.figure()
- ax2 = fig2.add_subplot()
- y = f('Data.csv', country_name, 2002, 2020)
- ax2.bar(x, y, width=0.5)
- ax2.set_xlabel('Years') # позначення вісі абсцис
- ax2.set_ylabel('Life expectancy') # позначення е вісі ординат
- ax2.set_title('Life expectancy at birth, total (years): ' + country_name) # назва графіка
- plt.show()
- №Завдання 3
- import json
- import numpy as np
- import matplotlib.pyplot as plt
- with open('file_name.json', "r") as json_name:
- y = np.array([], str)
- x1 = np.array([], int)
- x2 = np.array([], int)
- for i, j in dict(json.load(json_name)).items():
- y = np.append(y, i)
- x1 = np.append(x1, j[0])
- x2 = np.append(x2, j[1])
- index_max1 = x1.argmax()
- index_max2 = x2.argmax()
- explode1 = [0] * len(y)
- explode1[index_max1] = 0.03
- explode2 = [0] * len(y)
- explode2[index_max2] = 0.03
- fig1 = plt.figure()
- ax1 = fig1.add_subplot()
- ax1.pie(x1, labels=y, autopct='%1.1f%%', explode=explode1)
- ax1.set_title('Circulation') # назва графіка
- fig2 = plt.figure()
- ax2 = fig2.add_subplot()
- ax2.pie(x2, labels=y, autopct='%1.1f%%', explode=explode2)
- ax2.set_title('Price') # назва графіка
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement