import csv
import numpy as np
import matplotlib.pyplot as plt
from copy import deepcopy


merkblatt_katal_pn25 = ['merkblatt_katal_pn25.csv']



with open(merkblatt_katal_pn25[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    pocet_radku_katal_pn25 = 0
    for radky in cteni_radku:
        pocet_radku_katal_pn25 += 1



with open(merkblatt_katal_pn25[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    _cteni_radku = list(cteni_radku)
    nazvy_promennych = _cteni_radku[0]
    nazvy_jednotek = _cteni_radku[1]



nazev_osy_x = 'di'
nazev_osy_y = 'hF_provozBB'
nazev_osy_y1 = 'hF_montazBB'
nazev_osy_y2 = 'hF'

sloupec_promenna_x = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_x:
        break
    else:
        sloupec_promenna_x += 1

sloupec_promenna_y = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y:
        break
    else:
        sloupec_promenna_y += 1

sloupec_promenna_y1 = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y1:
        break
    else:
        sloupec_promenna_y1 += 1

sloupec_promenna_y2 = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y2:
        break
    else:
        sloupec_promenna_y2 += 1



hodnoty_x_merkblatt_katal_pn25 = []
hodnoty_y_merkblatt_katal_pn25 = []
hodnoty_y1_merkblatt_katal_pn25 = []
hodnoty_y2_merkblatt_katal_pn25 = []
with open(merkblatt_katal_pn25[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    for radky in cteni_radku:
        hodnoty_x_merkblatt_katal_pn25.append(radky[sloupec_promenna_x])
        hodnoty_y_merkblatt_katal_pn25.append(radky[sloupec_promenna_y])
        hodnoty_y1_merkblatt_katal_pn25.append(radky[sloupec_promenna_y1])
        hodnoty_y2_merkblatt_katal_pn25.append(radky[sloupec_promenna_y2])


fig, ax = plt.subplots(figsize=(15,8))

ax.plot(hodnoty_x_merkblatt_katal_pn25[2:-1], hodnoty_y_merkblatt_katal_pn25[2:-1], 'o-', label='$h_f,provoz$')
ax.plot(hodnoty_x_merkblatt_katal_pn25[2:-1], hodnoty_y1_merkblatt_katal_pn25[2:-1], 'o-', label='$h_f,montaz$')
ax.plot(hodnoty_x_merkblatt_katal_pn25[2:-1], hodnoty_y2_merkblatt_katal_pn25[2:-1], 'o-', label='$h_f$')
ax.grid()

ax.set_xlabel('$d_i [mm]$')
ax.set_ylabel('$h_f,montaz,provoz $ $[mm]$')
ax.legend(loc='upper left', shadow=False)
plt.title('Merkblatt (PN25)')
plt.savefig('zavislost_'+nazev_osy_x+'_na_'+nazev_osy_y+'.png',dpi=300)
plt.show()
