Advertisement
lancernik

AIS4

Apr 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.20 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Mar 25 23:38:31 2019
  4.  
  5. @author: laura
  6. """
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. import os
  10. import csv
  11. import pandas as pd
  12.  
  13.  
  14. #Kolos
  15. #mnozenie macierzy macierz_A @ macierz_B
  16. #array = np.random.poisson(lam=0.5, (500, 10, 1))
  17. #array_t = array.waspaxes(500, 1, 10) #pozdro xd transponowanie wektorow
  18. #for in range (500):
  19. # outer_result = np.outer(array[i,:,:], array.tranpsoed[i, :, :])
  20.  
  21. #na nastepnym kolokwium wizualizaja i wczytywanie danych
  22.  
  23. #Zadanie 1
  24. #Wygeneruj dwa losowe wektory rozkładu jednorodnego w przedziale [0, 10] o długosci 500. Znajdz punkty,
  25. #które znajduja sie w wewnatrz koła o srodku (5, 5) i promieniu równym 3. Korzystajac z tych informacji.
  26. #Narysuj wykres jak ponizej (zwróc uwage na osie, podpisy):
  27.  
  28. #x = np.random.uniform(0, 10, 500)
  29. #y = np.random.rand(500)*10
  30. #
  31. ##wartosci w obrebie kola
  32. #inside = np.square(x - 5) + np.square(y -5) <= 3*3
  33. #x_inside = x[inside]
  34. #y_inside = y[inside]
  35. #
  36. ##warotsci poza kolem
  37. #outside = np.logical_not(inside)
  38. #x_outside = x[outside]
  39. #y_outside = y[outside]
  40. #
  41. ##tworzenie wykresu
  42. #plt.figure()
  43. #plt.plot(x_inside, y_inside, "b*")
  44. #plt.plot(x_outside, y_outside, "r*")
  45. #
  46. ##zmiana skali
  47. #plt.xlim(0,10)
  48. #plt.ylim(0,10)
  49. #
  50. ##podpis osi
  51. #plt.xlabel("X Coordinate")
  52. #plt.ylabel("Y Coordinate")
  53. #
  54. ##legenda
  55. #plt.legend(["inside", "outside"])
  56. #
  57. ##wyswietlanie wykresu
  58. #plt.show()
  59.  
  60.  
  61. #x= np.arange(0, 8)
  62. #y = np.array([4.505,1.6936,0.6218,0.24911,0.10342,0.04546,0.022446,0.012452 ])
  63. #plt.figure()
  64. #plt.plot(x, y, 'b')
  65. #plt.grid(True)
  66. #plt.ylabel("Wartosc napięcia [V]")
  67. #plt.xlabel("Czas [10s]")
  68. #plt.show()
  69.  
  70.  
  71. #x= np.arange(0, 8)
  72. #y=np.array([0.24958, 02.5141, 03.7538, 04.2353, 04.4044, 04.4809, 04.5067, 04.5184 ])
  73. #plt.plot(x, y, 'b')
  74. #plt.grid(True)
  75. #plt.ylabel("Wartosc napięcia [V]")
  76. #plt.xlabel("Czas [10s]")
  77. #plt.show()
  78.  
  79.  
  80. #zadanie 2
  81. #Wygeneruj sinusoide dla argumentów od [0, 2pi] składajaca sie z 10000 równomiernie wygenerowanych próbek.
  82. #Przesun sinusoide 8 razy, za kazdym razem o kolejne p/8
  83.  
  84. #x = np.linspace(0, 2 *( np.pi), 10000)
  85. #y = np.sin(x)
  86. #y_1 = np.sin(x - (np.pi/8))
  87. ##y_1 = np.roll(y, int(1000/16))
  88. #y_2 = np.sin(x - np.pi*(2/8))
  89. #y_3 = np.sin(x - np.pi*(3/8))
  90. #y_4 = np.sin(x - np.pi*(4/8))
  91. #y_5 = np.sin(x - np.pi*(5/8))
  92. #y_6 = np.sin(x - np.pi*(6/8))
  93. #y_7 = np.sin(x - np.pi*(7/8))
  94. #y_8 = np.sin(x - np.pi*(8/8))
  95. #
  96. ##tworzenie wykresów
  97. #plt.figure()
  98. #plt.plot(x, y, color = 'red', linestyle = '--')
  99. #plt.plot(x, y_1, color = 'lime')
  100. #plt.plot(x, y_2, color = 'cyan', linestyle = '-.')
  101. #plt.plot(x, y_3, color = 'cyan', linestyle = ':')
  102. #plt.plot(x, y_4, color = 'yellow', linestyle = '--')
  103. #plt.plot(x, y_5, color = 'olive')
  104. #plt.plot(x, y_6, color = 'chartreuse', linestyle = '-.')
  105. #plt.plot(x, y_7, color = 'black', linestyle = ':')
  106. #plt.plot(x, y_8, color = 'fuchsia', linestyle = '--')
  107. #
  108. ##zmiana skali
  109. #plt.xlim(0, 8)
  110. #plt.ylim(-1.1, 1.1)
  111. #
  112. ##podpis osi
  113. #plt.xlabel('X')
  114. #plt.ylabel('Y')
  115. #
  116. ##kratkowanie
  117. #plt.grid(True)
  118. #
  119. ##legenda
  120. #plt.legend([r"$sin(x)$", r"$sin(x - \frac{\pi}{8})$", r"$sin(x - \frac{2*\pi}{8})$",
  121. # r"$sin(x - \frac{3*\pi}{8})$", r"$sin(x - \frac{4*\pi}{8})$", r"$sin(x - \frac{5*\pi}{8})$",
  122. # r"$sin(x - \frac{6*\pi}{8})$", r"$sin(x - \frac{7*\pi}{8})$", r"$sin(x - \pi)$"])
  123. #
  124. ## wyświetlenie wykresu na ekranie
  125. #plt.show()
  126.  
  127.  
  128. #zadanie 3
  129. #albo pakiet panda z funkcja panda! naucz sie na kolos, czasem sie nie da pandą wczytac
  130. #fukcja support do tworzenia malyhc wykresow w duzym wykresie
  131. #na zewnatrz wyakstrahuj(?) funckje, ktora cos tam zrobi
  132.  
  133. #sciezka do pliku
  134. #current_dir = os.path.abspath(os.path.dirname(__file__))
  135. #data_path = os.path.join(current_dir, "Data")
  136. #csv_path = os.path.join(data_path, "iris.csv")
  137. ##
  138. ###wczytywanie pandas
  139. #dataset = pd.read_csv(csv_path)
  140. ##unikalne wartosci dla variety
  141. #print(dataset['variety'].unique())
  142. ##tworzenie 3 ramek danych dla poszczegolnych gatunkow
  143. #setosa=dataset[dataset['variety']=='Setosa']
  144. #versicolor =dataset[dataset['variety']=='Versicolor']
  145. #virginica =dataset[dataset['variety']=='Virginica']
  146. #
  147. #
  148. #
  149. ##to drugie wczytywanie
  150. ##with open(csv_path) as csv_file:
  151. ## output_dict = dict()
  152. ## csv_reader = csv.reader(csv_file)
  153. ## first_row = next(csv_reader)
  154. ## for item in first_row:
  155. ## output_dict[item] = []
  156. ## for item in csv_reader:
  157. ## for i in range(len(item)):
  158. ## try:
  159. ## output_dict[first_row[i]].append(float(item[i]))
  160. ## except:
  161. ## output_dict[first_row[i]].append(item[i])
  162. ##
  163. ## for key in output_dict.keys():
  164. ## try:
  165. ## output_dict[key] = np.array(output_dict[key], dtype=np.float)
  166. ## except:
  167. ## pass
  168. #
  169. #
  170. #podstawowe funckje
  171. #plt.figure()
  172. #fig,ax=plt.subplots(2,3,figsize=(21, 10))
  173. #
  174. ##tworzenie poszczegolnych wykresow
  175. #setosa.plot(x="sepal.length", y="sepal.width", kind="scatter",ax=ax[0][0],label='setosa',color='r')
  176. #versicolor.plot(x="sepal.length",y="sepal.width",kind="scatter",ax=ax[0][0],label='versicolor',color='g')
  177. #virginica.plot(x="sepal.length", y="sepal.width", kind="scatter",ax=ax[0][0], label='virginica', color='b')
  178. #
  179. #setosa.plot(x="sepal.length", y="petal.length", kind="scatter",ax=ax[0][1],label='setosa',color='r')
  180. #versicolor.plot(x="sepal.length",y="petal.length",kind="scatter",ax=ax[0][1],label='versicolor',color='g')
  181. #virginica.plot(x="sepal.length", y="petal.length", kind="scatter",ax=ax[0][1], label='virginica', color='b')
  182. #
  183. #setosa.plot(x="sepal.length", y="petal.width", kind="scatter",ax=ax[0][2],label='setosa',color='r')
  184. #versicolor.plot(x="sepal.length",y="petal.width",kind="scatter",ax=ax[0][2],label='versicolor',color='g')
  185. #virginica.plot(x="sepal.length", y="petal.width", kind="scatter",ax=ax[0][2], label='virginica', color='b')
  186. #
  187. #setosa.plot(x="sepal.width", y="petal.length", kind="scatter",ax=ax[1][0],label='setosa',color='r')
  188. #versicolor.plot(x="sepal.width",y="petal.length",kind="scatter",ax=ax[1][0],label='versicolor',color='g')
  189. #virginica.plot(x="sepal.width", y="petal.length", kind="scatter",ax=ax[1][0], label='virginica', color='b')
  190. #
  191. #setosa.plot(x="sepal.width", y="petal.width", kind="scatter",ax=ax[1][1],label='setosa',color='r')
  192. #versicolor.plot(x="sepal.width",y="petal.width",kind="scatter",ax=ax[1][1],label='versicolor',color='g')
  193. #virginica.plot(x="sepal.width", y="petal.width", kind="scatter",ax=ax[1][1], label='virginica', color='b')
  194. #
  195. #setosa.plot(x="petal.width", y="petal.width", kind="scatter",ax=ax[1][2],label='setosa',color='r')
  196. #versicolor.plot(x="petal.width",y="petal.width",kind="scatter",ax=ax[1][2],label='versicolor',color='g')
  197. #virginica.plot(x="petal.width", y="petal.width", kind="scatter",ax=ax[1][2], label='virginica', color='b')
  198. #
  199. #
  200. ##tworzenie kratkowania i opisu osi
  201. #ax[0][0].set(ylabel='Sepal Width')
  202. #ax[0][0].grid(True)
  203. #
  204. #ax[0][1].set( ylabel='Petal Length')
  205. #ax[0][1].grid(True)
  206. #
  207. #ax[0][2].set( ylabel='Petal Width')
  208. #ax[0][2].grid(True)
  209. #
  210. #ax[1][0].set( ylabel='Petal Length')
  211. #ax[1][0].grid(True)
  212. #
  213. #ax[1][1].set( ylabel='Petal Width')
  214. #ax[1][1].grid(True)
  215. #
  216. #ax[1][2].set( ylabel='Petal Width')
  217. #ax[1][2].grid(True)
  218. #
  219. #
  220. ##tworzenie legendy
  221. #ax[0][0].legend()
  222. #ax[0][1].legend()
  223. #ax[0][2].legend()
  224. #ax[1][0].legend()
  225. #ax[1][1].legend()
  226. #ax[1][2].legend()
  227. #
  228. #
  229. #plt.tight_layout()
  230. #plt.show()
  231.  
  232. #Zadanie 4
  233. #sciezka do pliku
  234. #current_dir = os.path.abspath(os.path.dirname(__file__))
  235. #data_path = os.path.join(current_dir, "Data")
  236. #csv_path = os.path.join(data_path, "factbook.csv")
  237.  
  238. ##to drugie wczytywanie
  239. #with open(csv_path) as csv_file:
  240. # output_dict = dict()
  241. # csv_reader = csv.reader(csv_file)
  242. # first_row = next(csv_reader)
  243. # for item in first_row:
  244. # output_dict[item] = []
  245. # for item in csv_reader:
  246. # for i in range(len(item)):
  247. # try:
  248. # output_dict[first_row[i]].append(float(item[i]))
  249. # except:
  250. # output_dict[first_row[i]].append(item[i])
  251. #
  252. # for key in output_dict.keys():
  253. # try:
  254. # output_dict[key] = np.array(output_dict[key], dtype=np.float)
  255. # except:
  256. # pass
  257.  
  258.  
  259. #Zadanie 5
  260. #sciezka do pliku
  261. #current_dir = os.path.abspath(os.path.dirname(__file__))
  262. #data_path = os.path.join(current_dir, "Data")
  263. #csv_path = os.path.join(data_path, "cars.csv")
  264. ##wczytywanie pliku
  265. #dataset = pd.read_csv(csv_path, sep = ';', )
  266. ##dane
  267. ##opusczanie wierszego wiersza
  268. #dataset = dataset.drop(dataset.index[0])
  269. ##wydobywanie 2 kolumn- acceleration i horsepower
  270. #dane = dataset[["Acceleration", "Horsepower"]]
  271. ##zmienianie typu danych na float
  272. #dane=dane.astype(float)
  273. ##zostawianie w dataframe takich wierszow, w ktorych wartosci z kolumny horsepower nie rownaja sie 0
  274. #dane = dane[(dane['Horsepower'] !=0)]
  275. #
  276. #plt.figure()
  277. #colors = np.random.rand(400)
  278. #dane.plot.scatter(x = 'Horsepower', y = 'Acceleration', c=colors, colormap = 'gist_ncar' )
  279. #plt.grid(True)
  280. #plt.xlabel('Horsepower [kW]')
  281. #plt.ylabel('Acceleration [uknown]')
  282. #plt.tight_layout()
  283. #plt.show()
  284.  
  285.  
  286.  
  287. #PODZIALKA RADNOWOE KOORU!?!?
  288.  
  289. #zadanie 6
  290. ##sciezka do pliku
  291. #current_dir = os.path.abspath(os.path.dirname(__file__))
  292. #data_path = os.path.join(current_dir, "Data")
  293. #csv_path = os.path.join(data_path, "iris.csv")
  294. ##
  295. ###wczytywanie pandas
  296. #dataset = pd.read_csv(csv_path)
  297. ##unikalne wartosci dla variety
  298. ##print(dataset['variety'].unique())
  299. ##tworzenie 3 ramek danych dla poszczegolnych gatunkow
  300. #setosa=dataset[dataset['variety']=='Setosa']
  301. #versicolor =dataset[dataset['variety']=='Versicolor']
  302. #virginica =dataset[dataset['variety']=='Virginica']
  303.  
  304. ##tworzenie korelacji
  305. ##wydzielenie odpowiednich kolumn
  306. #df = dataset[['sepal.length', 'sepal.width', 'petal.length', 'petal.width']]
  307. #print('korelacja')
  308. #print(df.corr(method ='kendall'))
  309. #
  310. ##obliczanie mean
  311. #print('mean')
  312. #print("sepal.lenght", round(np.mean(dataset['sepal.length']),6))
  313. #print("sepal.width", round(np.mean(dataset['sepal.width']),6))
  314. #print("petal.lenght", round(np.mean(dataset['petal.length']),6))
  315. #print("petal.width", round(np.mean(dataset['petal.width']),6))
  316. #
  317. ##obliczanie std
  318. #print('std')
  319. #print("sepal.lenght", round(np.std(dataset['sepal.length']),6))
  320. #print("sepal.width", round(np.std(dataset['sepal.width']),6))
  321. #print("petal.lenght", round(np.std(dataset['petal.length']),6))
  322. #print("petal.width", round(np.std(dataset['petal.width']),6))
  323.  
  324.  
  325. #to drugie wczytywanie
  326. #with open(csv_path) as csv_file:
  327. # output_dict = dict()
  328. # csv_reader = csv.reader(csv_file)
  329. # first_row = next(csv_reader)
  330. # for item in first_row:
  331. # output_dict[item] = []
  332. # for item in csv_reader:
  333. # for i in range(len(item)):
  334. # try:
  335. # output_dict[first_row[i]].append(float(item[i]))
  336. # except:
  337. # output_dict[first_row[i]].append(item[i])
  338. #
  339. # for key in output_dict.keys():
  340. # try:
  341. # output_dict[key] = np.array(output_dict[key], dtype=np.float)
  342. # except:
  343. # pass
  344.  
  345.  
  346. #podstawowe funckje
  347. #plt.figure()
  348. #fig,ax=plt.subplots(2,3,figsize=(21, 10))
  349. #
  350. ##tworzenie poszczegolnych wykresow
  351. #setosa.plot(x="sepal.length", y="sepal.width", kind="scatter", marker = '*', ax=ax[0][0],label='setosa',color='r')
  352. #versicolor.plot(x="sepal.length",y="sepal.width",kind="scatter",marker = '*',ax=ax[0][0],label='versicolor',color='g')
  353. #virginica.plot(x="sepal.length", y="sepal.width", kind="scatter",marker = '*',ax=ax[0][0], label='virginica', color='b')
  354. #
  355. #setosa.plot(x="sepal.length", y="petal.length", kind="scatter",marker = '*',ax=ax[0][1],label='setosa',color='r')
  356. #versicolor.plot(x="sepal.length",y="petal.length",kind="scatter",marker = '*',ax=ax[0][1],label='versicolor',color='g')
  357. #virginica.plot(x="sepal.length", y="petal.length", kind="scatter",marker = '*',ax=ax[0][1], label='virginica', color='b')
  358. #
  359. #setosa.plot(x="sepal.length", y="petal.width", kind="scatter",marker = '*',ax=ax[0][2],label='setosa',color='r')
  360. #versicolor.plot(x="sepal.length",y="petal.width",kind="scatter",marker = '*',ax=ax[0][2],label='versicolor',color='g')
  361. #virginica.plot(x="sepal.length", y="petal.width", kind="scatter",marker = '*',ax=ax[0][2], label='virginica', color='b')
  362. #
  363. #setosa.plot(x="sepal.width", y="petal.length", kind="scatter",marker = '*',ax=ax[1][0],label='setosa',color='r')
  364. #versicolor.plot(x="sepal.width",y="petal.length",kind="scatter",marker = '*',ax=ax[1][0],label='versicolor',color='g')
  365. #virginica.plot(x="sepal.width", y="petal.length", kind="scatter",marker = '*',ax=ax[1][0], label='virginica', color='b')
  366. #
  367. #setosa.plot(x="sepal.width", y="petal.width", kind="scatter",marker = '*',ax=ax[1][1],label='setosa',color='r')
  368. #versicolor.plot(x="sepal.width",y="petal.width",kind="scatter",marker = '*',ax=ax[1][1],label='versicolor',color='g')
  369. #virginica.plot(x="sepal.width", y="petal.width", kind="scatter",marker = '*',ax=ax[1][1], label='virginica', color='b')
  370. #
  371. #setosa.plot(x="petal.width", y="petal.width", kind="scatter",marker = '*',ax=ax[1][2],label='setosa',color='r')
  372. #versicolor.plot(x="petal.width",y="petal.width",kind="scatter",marker = '*',ax=ax[1][2],label='versicolor',color='g')
  373. #virginica.plot(x="petal.width", y="petal.width", kind="scatter",marker = '*',ax=ax[1][2], label='virginica', color='b')
  374.  
  375. #Zadanie 9
  376. #sciezka do pliku
  377. current_dir = os.path.abspath(os.path.dirname(__file__))
  378. data_path = os.path.join(current_dir, "Data")
  379. csv_path = os.path.join(data_path, "iris.csv")
  380. #
  381. ##wczytywanie pandas
  382. dataset = pd.read_csv(csv_path)
  383. #unikalne wartosci dla variety
  384. #print(dataset['variety'].unique())
  385. #tworzenie 3 ramek danych dla poszczegolnych gatunkow
  386. setosa=dataset[dataset['variety']=='Setosa']
  387. versicolor =dataset[dataset['variety']=='Versicolor']
  388. virginica =dataset[dataset['variety']=='Virginica']
  389.  
  390. #podstawowe funckje
  391. plt.figure()
  392.  
  393.  
  394.  
  395.  
  396. #tworzenie histogramow
  397. #fig,ax=plt.subplots(2,2,figsize=(21, 10))
  398. #
  399. #
  400. ###tworzenie poszczegolnych histogramow
  401. #setosa.hist(column="sepal.length", density='True',ax=ax[0][0],label='setosa',color='r')
  402. #versicolor.hist(column="sepal.length",density='True',ax=ax[0][0],label='versicolor',color='g')
  403. #virginica.hist(column="sepal.length",density='True',ax=ax[0][0], label='virginica', color='b')
  404. #
  405. #setosa.hist(column="sepal.width", density='True',ax=ax[0][1],label='setosa',color='r')
  406. #versicolor.hist(column="sepal.width",density='True',ax=ax[0][1],label='versicolor',color='g')
  407. #virginica.hist(column="sepal.width",density='True',ax=ax[0][1], label='virginica', color='b')
  408. #
  409. #setosa.hist(column="petal.length", density='True',ax=ax[1][0],label='setosa',color='r')
  410. #versicolor.hist(column="petal.length",density='True',ax=ax[1][0],label='versicolor',color='g')
  411. #virginica.hist(column="petal.length",density='True',ax=ax[1][0], label='virginica', color='b')
  412. #
  413. #setosa.hist(column="petal.width", density='True',ax=ax[1][1],label='setosa',color='r')
  414. #versicolor.hist(column="petal.width",density='True',ax=ax[1][1],label='versicolor',color='g')
  415. #virginica.hist(column="petal.width", density='True',ax=ax[1][1], label='virginica', color='b')
  416. #
  417. #####Jak usunać ten tytul?
  418. #
  419. ##tworzenie kratkowania i opisu osi
  420. #ax[0][0].set(ylabel='Denisity')
  421. #ax[0][0].set(xlabel='Sepal Length')
  422. #ax[0][0].grid(True)
  423. #ax[0][0].set()
  424. #
  425. #ax[0][1].set( ylabel='Denisity')
  426. #ax[0][1].set( xlabel='Sepal Width')
  427. #ax[0][1].grid(True)
  428. #
  429. #ax[1][0].set( ylabel='Denisity')
  430. #ax[1][0].set( xlabel='Petal Length')
  431. #ax[1][0].grid(True)
  432. #
  433. #ax[1][1].set( ylabel='Denisity')
  434. #ax[1][1].set( xlabel='Petal Width')
  435. #
  436. #ax[1][1].grid(True)
  437. #
  438. #
  439. ##tworzenie legendy
  440. #ax[0][0].legend()
  441. #ax[0][1].legend()
  442. #ax[1][0].legend()
  443. #ax[1][1].legend()
  444. #
  445. #
  446. #plt.tight_layout()
  447. #plt.show()
  448.  
  449.  
  450.  
  451.  
  452. #tworzenie pudelek
  453.  
  454. #pozyskiwanie danych
  455. setosa_modified = setosa[['sepal.length','sepal.width','petal.length','petal.width']]
  456. #tworzenie pudelka dla setosy
  457. setosa.plot.box(setosa_modified, grid = "True")
  458. #pozyskiwanie danych
  459. virginica_modified = virginica[['sepal.length','sepal.width','petal.length','petal.width']]
  460. #tworzenie pudelka dla setosy
  461. virginica.plot.box(virginica_modified, grid = "True")
  462. #pozyskiwanie danych
  463. versicolor_modified = versicolor[['sepal.length','sepal.width','petal.length','petal.width']]
  464. #tworzenie pudelka dla setosy
  465. versicolor.plot.box(versicolor_modified, grid = "True")
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486. # -*- coding: utf-8 -*-
  487. """
  488. Created on Thu Apr 11 13:15:55 2019
  489.  
  490. @author: lancernik
  491. """
  492.  
  493.  
  494.  
  495.  
  496.  
  497. #========= Tutorial MatplotLib - 2 ===================================
  498.  
  499.  
  500. #import matplotlib.pyplot as plt
  501. #
  502. #x=[1,2,3]
  503. #y=[5,7,4]
  504. #
  505. #x2 = [1,2,3]
  506. #y2 = [10,14,12]
  507. #
  508. #
  509. #plt.plot(x,y, label='First line')
  510. #plt.plot(x2,y2, label='Secound line') #Rysuje na diagamie
  511. #
  512. #plt.xlabel('Plot number') #opisuje os x
  513. #plt.ylabel('Imporatnat var') #opisuje os y
  514. #plt.title('Interesting Graph\nCheck it out') #Dodaje u gory
  515. #
  516. #plt.legend() #Pokazauje legende opisana w label przy plot
  517. #plt.show() #Rysuje diagram
  518.  
  519.  
  520. #========= Tutorial MatplotLib - 3 ===================================
  521.  
  522. # ----- W Y K R E S B A R -----
  523. #import matplotlib.pyplot as plt
  524. #
  525. #x = [2,4,6,8,10]
  526. #y = [6,4,6,3,6]
  527. #
  528. #
  529. #x2 =[1,3,5,9,11]
  530. #y2 = [7,8,2,4,2]
  531. #
  532. #plt.bar(x,y,label='Bars1', color='green')
  533. #plt.bar(x2,y2,label='Bars2', color = 'r')
  534. #
  535. #
  536. #plt.xlabel('x')
  537. #plt.ylabel('y')
  538. #plt.title('Interesting Graph\nCheck it out')
  539. #plt.legend()
  540. #plt.show()
  541.  
  542.  
  543.  
  544. # ----- W Y K R E S B A R 2 -----
  545.  
  546.  
  547.  
  548. #import matplotlib.pyplot as plt
  549. #
  550. #population_ages = [22,55,62,41,22,34,42,4,9,102,106,102,56,32,63]
  551. #
  552. #ids = [x for x in range(len(population_ages))]
  553. #
  554. #plt.bar(ids,population_ages)
  555. #
  556. #
  557. #plt.xlabel('x')
  558. #plt.ylabel('y')
  559. #plt.title('Interesting Graph\nCheck it out')
  560. #plt.legend()
  561. #plt.show()
  562.  
  563.  
  564.  
  565.  
  566. # ----- W Y K R E S H I S T 2 -----
  567.  
  568. #
  569. #import matplotlib.pyplot as plt
  570. #
  571. #population_ages = [22,55,62,41,22,34,42,4,9,102,106,102,56,32,63]
  572. #
  573. #bins = [0,10,20,30,40,50,60,70,90,90,100,110,120,130]
  574. #
  575. #plt.hist(population_ages,bins,histtype='bar',rwidth=0.8)
  576. #
  577. #plt.xlabel('x')
  578. #plt.ylabel('y')
  579. #plt.title('Interesting Graph\nCheck it out')
  580. #plt.legend()
  581. #plt.show()
  582.  
  583. #========= Tutorial MatplotLib - 4 ===================================
  584.  
  585.  
  586. #
  587. #import matplotlib.pyplot as plt
  588. #
  589. #x = [1,2,3,4,5,6,7,8]
  590. #y = [5,2,5,7,4,3,2,6]
  591. #
  592. #plt.scatter(x,y,label='skitscat',color='k', s=10)
  593. #
  594. #plt.xlabel('x')
  595. #plt.ylabel('y')
  596. #plt.title('Interesting Graph\nCheck it out')
  597. #plt.legend()
  598. #plt.show()
  599.  
  600.  
  601.  
  602. #========= Tutorial MatplotLib - 5 ===================================
  603.  
  604.  
  605.  
  606. #import matplotlib.pyplot as plt
  607. #
  608. #days = [1,2,3,4,5]
  609. #sleeping = [7,8,6,11,7]
  610. #eating = [2,3,4,3,2]
  611. #working = [7,8,7,2,2]
  612. #playing = [8,5,7,8,13]
  613. #
  614. #
  615. ##---Fake plots to mage a legend
  616. #plt.plot([],[],color='m',label='Sleeping',linewidth=5)
  617. #plt.plot([],[],color='c',label='Eating',linewidth=5)
  618. #plt.plot([],[],color='r',label='Wokring',linewidth=5)
  619. #plt.plot([],[],color='k',label='Playing',linewidth=5)
  620. ##---Fake plots to mage a legend
  621. #
  622. #
  623. #
  624. #plt.stackplot(days, sleeping, eating, working, playing, colors=['m','c','r','k'])
  625. #
  626. #plt.xlabel('x')
  627. #plt.ylabel('y')
  628. #plt.title('Interesting Graph\nCheck it out')
  629. #plt.legend()
  630. #plt.show()
  631.  
  632.  
  633.  
  634.  
  635.  
  636. #========= Tutorial MatplotLib - 6 ===================================
  637.  
  638. #import matplotlib.pyplot as plt
  639. #
  640. #days = [1,2,3,4,5]
  641. #sleeping = [7,8,6,11,7]
  642. #eating = [2,3,4,3,2]
  643. #working = [7,8,7,2,2]
  644. #playing = [8,5,7,8,13]
  645. #
  646. #slices = [7,2,2,13]
  647. #activities = ['Sleeping','Eating','Working','Playing']
  648. #cols = ['c','m','r','g']
  649. #
  650. #plt.pie(slices, labels=activities,
  651. # colors = cols,
  652. # startangle = 90, #obraca
  653. # shadow = True,
  654. # explode = (0,0.1,0,0), #wycina kawalek
  655. # autopct='%1.1f%%') #Pokazuje procjenty
  656. #
  657. #
  658. #
  659. #plt.xlabel('x')
  660. #plt.ylabel('y')
  661. #plt.title('Interesting Graph\nCheck it out')
  662. #plt.legend()
  663. #plt.show()
  664.  
  665.  
  666.  
  667.  
  668.  
  669. #========= Tutorial MatplotLib - 7 ===================================
  670.  
  671.  
  672. #x
  673. #x
  674. #x
  675. #x
  676. #x
  677.  
  678.  
  679.  
  680.  
  681. #========= Tutorial MatplotLib - 8 ===================================
  682.  
  683.  
  684. #import matplotlib.pyplot as plt
  685. #import numpy as np
  686. #import urllib
  687. #import matplotlib.dates as mdates
  688. #
  689. #def graph_data(stock):
  690. #
  691. # stock_price_url = 'https://pythonprogramming.net/yahoo_finance_replacement'
  692. #
  693. # source_code = urllib.request.urlopen(stock_price_url).read().decode()
  694. #
  695. # stock_data= []
  696. # split_source = source_code.split('\n')
  697. #
  698. # for line in split_source:
  699. # split_line = line.split(',')
  700. # if len(split_line) == 6:
  701. # if'values' not in line:
  702. # stock_data.append(line)
  703. #
  704. # date,closep, highp, lowp, openp, volume = np.loadtxt(stock_data,
  705. # delimiter =',',
  706. # unpack=True,
  707. # converters={0: bytespdate2num('%Y%m%d))}
  708. #
  709. # plt.xlabel('x')
  710. # plt.ylabel('y')
  711. # plt.title('Interesting Graph\nCheck it out')
  712. # plt.legend()
  713. # plt.show()
  714. #
  715. #
  716. #graph_data('TSLA')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement