- Author:
- Alan Garny <agarny@hellix.com>
- Date:
- 2021-06-16 09:49:10+12:00
- Desc:
- Don't require Tkinter.
This is not needed on macOS (and maybe not on Linux either), but is definitely needed on Windows.
- Permanent Source URI:
- https://staging.physiomeproject.org/workspace/648/rawfile/c2034e3322dd75a7a15067f35a300bac08101ab9/Figure5-plot.py
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# read the csv file extracted from sedml file
data = pd.read_csv('Figure5.csv')
# clean the data
data = data.loc[:, ~data.columns.str.contains('^Unnamed')]
data = data.drop(columns=["time"])
cl = []
for i in range(0, 7):
cl.append(data.index[data.T.iloc[i] == data.T.iloc[i][700:1500].min()].values[-1] -
data.index[data.T.iloc[i] == data.T.iloc[i][200:700].min()].values[-1])
print(cl)
y_shift = [-15, -10, -5, 0, 5, 10, 15]
plt.figure(figsize=(14, 14))
plt.subplot(2, 2, 1)
plt.plot(y_shift, cl, 'navy', linestyle='', marker='D', markersize='14', label='', linewidth=3)
plt.grid()
plt.ylim(400, 1200)
plt.yticks(np.arange(400, 1300, 200))
plt.xlabel('y$_{\infty}$ shift', fontsize=16)
plt.tick_params(axis='both', labelsize=14)
plt.ylabel('CL (ms)', fontsize=16)
plt.title('A', loc='left', y=1.05, x=-0.06, fontsize='20')
DDR = []
for i in range(0, 7):
A = data.T.iloc[i][200:700].min()
end = (data.index[data.T.iloc[i] == data.T.iloc[i][200:700].min()][-1] + 100)
B = data.T.iloc[i][end]
DDR.append((B - A) * 10)
print(DDR)
plt.subplot(2, 2, 2)
plt.plot(y_shift, DDR, 'navy', linestyle='', marker='D', markersize='14', label='', linewidth=3)
plt.grid()
plt.ylim(20, 80)
plt.yticks(np.arange(20, 90, 20))
plt.xlabel('y$_{\infty}$ shift', fontsize='16')
plt.ylabel('DDR$_{100}$ (mV/s)', fontsize='16')
plt.tick_params(axis='both', labelsize=14)
plt.title('B', loc='left', y=1.05, x=-0.06, fontsize='20')
MDP = []
for i in range(0, 7):
A = data.T.iloc[i].min()
MDP.append(A)
print(MDP)
plt.subplot(2, 2, 3)
plt.plot(y_shift, MDP, 'navy', linestyle='', marker='D', markersize='14', label='')
plt.grid()
plt.ylim(-65, -50)
plt.yticks(np.arange(-65, -45, 5))
plt.xlabel('y$_{\infty}$ shift', fontsize='16')
plt.ylabel('MDP (mV)', fontsize='16')
plt.tick_params(axis='both', labelsize=14)
plt.title('C', loc='left', y=1.05, x=-0.06, fontsize='20')
APD = []
dys = []
for i in range(0, 7):
y = data.T.iloc[i][:601]
dy = np.gradient(y)
dys.append(dy)
a = dy[dy > 0.5]
neg = dy[dy < 0]
start = np.where(dy == a[0])
end = np.where(dy == neg[:int(neg.shape[0] * 0.9)][-1])
duration = end[0][-1] - start[0][-1]
APD.append(duration)
print(APD)
plt.subplot(2, 2, 4)
plt.plot(y_shift, APD, 'navy', linestyle='', marker='D', markersize='14', label='')
plt.grid()
plt.ylim(150, 190)
plt.xlabel('y$_{\infty}$ shift', fontsize='16')
plt.ylabel('APD$_{90}$ (ms)', fontsize='16')
plt.tick_params(axis='both', labelsize=14)
plt.title('D', loc='left', y=1.05, x=-0.06, fontsize='20')
plt.tight_layout(pad=0.5, w_pad=3, h_pad=3)
plt.savefig('Figure5.png')
plt.show()