Started working on Uli's comments

This commit is contained in:
nkoch1
2022-09-04 22:45:56 -04:00
parent c2c6a9cc78
commit c79560d191
32 changed files with 1164 additions and 83 deletions

Binary file not shown.

View File

@@ -94,7 +94,23 @@ def new_scatter(self, *args, **kwargs):
Axes.scatter = new_scatter
############## End hack. ##############
########################################################################################################################
#%% add gradient arrows
import matplotlib.pyplot as plt
import matplotlib.transforms
import matplotlib.path
from matplotlib.collections import LineCollection
def gradientaxis(ax, start, end, cmap, n=100,lw=1):
# Arrow shaft: LineCollection
x = np.linspace(start[0],end[0],n)
y = np.linspace(start[1],end[1],n)
points = np.array([x,y]).T.reshape(-1,1,2)
segments = np.concatenate([points[:-1],points[1:]], axis=1)
lc = LineCollection(segments, cmap=cmap, linewidth=lw,zorder=15)
lc.set_array(np.linspace(0,1,n))
ax.add_collection(lc)
return ax
#%%
#%%
def boxplot_with_markers(ax,max_width, alteration='shift', msize=3):
hlinewidth = 0.5
@@ -294,7 +310,7 @@ def plot_AUC_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration='
if mod == model_name_dict[model]:
ax.plot(df['alteration'], df[mod], color=clr_dict[mod], alpha=1, zorder=10, linewidth=2)
else:
ax.plot(df['alteration'], df[mod], color=clr_dict[mod],alpha=1, zorder=1, linewidth=1)
ax.plot(df['alteration'], df[mod], color=clr_dict[mod],alpha=0.5, zorder=1, linewidth=1)
if alteration=='shift':
ax.set_ylabel('Normalized $\Delta$AUC', labelpad=4)
@@ -304,6 +320,20 @@ def plot_AUC_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration='
y = df[model_name_dict[model]]
ax.set_xlim(x.min(), x.max())
ax.set_ylim(df[model_names].min().min(), df[model_names].max().max())
# x axis color gradient
cvals = [-2., 2]
colors = ['lightgrey', 'k']
norm = plt.Normalize(min(cvals), max(cvals))
tuples = list(zip(map(norm, cvals), colors))
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples)
(xstart, xend) = ax.get_xlim()
(ystart, yend) = ax.get_ylim()
print(ystart, yend)
start = (xstart, ystart * 1.0)
end = (xend, ystart * 1.0)
ax = gradientaxis(ax, start, end, cmap, n=100, lw=2)
ax.spines['bottom'].set_visible(False)
return ax
def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color2='dodgerblue'):
@@ -427,5 +457,6 @@ ax2.text(-0.075, 1.35, string.ascii_uppercase[8], transform=ax2.transAxes, size=
#save
fig.set_size_inches(cm2inch(20.75,12))
fig.savefig('./Figures/AUC_correlation.png', dpi=fig.dpi) #pdf #eps
fig.savefig('./Figures/AUC_correlation.pdf', dpi=fig.dpi) #pdf #eps
# fig.savefig('./Figures/AUC_correlation.png', dpi=fig.dpi) #pdf #eps
plt.show()

Binary file not shown.

View File

@@ -86,7 +86,7 @@ def add_scalebar(ax, matchx=True, matchy=True, hidex=True, hidey=True, **kwargs)
def plot_spike_train(ax, model='RS Pyramidal', stop=750):
model_spiking = pd.read_csv('./Figures/Data/model_spiking.csv')
stop_ind = np.int(np.argmin(np.abs(model_spiking['t'] - stop)))
stop_ind = int(np.argmin(np.abs(model_spiking['t'] - stop)))
ax.plot(model_spiking['t'][0:stop_ind], model_spiking[model][0:stop_ind], 'k', linewidth=1.5)
ax.set_ylabel('V')
ax.set_xlabel('Time [s]')
@@ -100,28 +100,28 @@ def plot_fI(ax, model='RS Pyramidal'):
model_F_inf = pd.read_csv('./Figures/Data/model_F_inf.csv')
if model=='RS Inhibitory':
ax.plot(model_F_inf['I_inhib'], model_F_inf[model], color='grey')
ax.plot(firing_values.loc['spike_ind', model], model_F_inf[model][np.int(np.argmin(np.abs(model_F_inf['I_inhib'] - firing_values.loc['spike_ind', model])))],
ax.plot(firing_values.loc['spike_ind', model], model_F_inf[model][int(np.argmin(np.abs(model_F_inf['I_inhib'] - firing_values.loc['spike_ind', model])))],
'.', color='k', markersize=3)
ax.plot(firing_values.loc['ramp_up', model],
model_F_inf[model][np.int(np.argmin(np.abs(model_F_inf['I_inhib'] - firing_values.loc['ramp_up', model])))],
model_F_inf[model][int(np.argmin(np.abs(model_F_inf['I_inhib'] - firing_values.loc['ramp_up', model])))],
'.', color='g', markersize=3)
ax.plot(firing_values.loc['ramp_down', model],
model_F_inf[model][np.int(np.argmin(np.abs(model_F_inf['I_inhib'] - firing_values.loc['ramp_down', model])))],
model_F_inf[model][int(np.argmin(np.abs(model_F_inf['I_inhib'] - firing_values.loc['ramp_down', model])))],
'.', color='r', markersize=3)
else:
ax.plot(model_F_inf['I'], model_F_inf[model], color='grey')
ax.plot(firing_values.loc['spike_ind', model],
model_F_inf[model][np.int(np.argmin(np.abs(model_F_inf['I'] - firing_values.loc['spike_ind', model])))],
model_F_inf[model][int(np.argmin(np.abs(model_F_inf['I'] - firing_values.loc['spike_ind', model])))],
'.', color='k', markersize=3)
ax.plot(firing_values.loc['ramp_up', model],
model_F_inf[model][np.int(np.argmin(np.abs(model_F_inf['I'] - firing_values.loc['ramp_up', model])))],
model_F_inf[model][int(np.argmin(np.abs(model_F_inf['I'] - firing_values.loc['ramp_up', model])))],
'.', color='g', markersize=3)
ax.plot(firing_values.loc['ramp_down', model],
model_F_inf[model][np.int(np.argmin(np.abs(model_F_inf['I'] - firing_values.loc['ramp_down', model])))],
model_F_inf[model][int(np.argmin(np.abs(model_F_inf['I'] - firing_values.loc['ramp_down', model])))],
'.', color='r', markersize=3)
f = 8
ax.set_ylabel('Frequency [Hz]', fontsize=f)
ax.set_xlabel('Current [pA]', fontsize=f)
ax.set_xlabel('Current [nA]', fontsize=f)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
@@ -188,7 +188,8 @@ for i in range(0,len(models)):
# save
fig.set_size_inches(cm2inch(17.6,20))
fig.savefig('./Figures/diversity_in_firing.png', dpi=fig.dpi) #pdf # eps
fig.savefig('./Figures/diversity_in_firing.pdf', dpi=fig.dpi) #pdf # eps
# fig.savefig('./Figures/diversity_in_firing.png', dpi=fig.dpi) #pdf # eps
plt.show()

Binary file not shown.

View File

@@ -95,7 +95,40 @@ def new_scatter(self, *args, **kwargs):
Axes.scatter = new_scatter
############## End hack. ##############
########################################################################################################################
#%% add gradient arrows
import matplotlib.pyplot as plt
import matplotlib.transforms
import matplotlib.path
from matplotlib.collections import LineCollection
def rainbowarrow(ax, start, end, cmap, n=50,lw=3):
# Arrow shaft: LineCollection
x = np.linspace(start[0],end[0],n)
y = np.linspace(start[1],end[1],n)
points = np.array([x,y]).T.reshape(-1,1,2)
segments = np.concatenate([points[:-1],points[1:]], axis=1)
lc = LineCollection(segments, cmap=cmap, linewidth=lw)
lc.set_array(np.linspace(0,1,n))
ax.add_collection(lc)
# Arrow head: Triangle
tricoords = [(0,-0.02),(0.025,0),(0,0.02),(0,-0.02)]
angle = np.arctan2(end[1]-start[1],end[0]-start[0])
rot = matplotlib.transforms.Affine2D().rotate(angle)
tricoords2 = rot.transform(tricoords)
tri = matplotlib.path.Path(tricoords2, closed=True)
ax.scatter(end[0],end[1], c=1, s=(4*lw)**2, marker=tri, cmap=cmap,vmin=0)
ax.autoscale_view()
return ax
def gradientaxis(ax, start, end, cmap, n=100,lw=1):
# Arrow shaft: LineCollection
x = np.linspace(start[0],end[0],n)
y = np.linspace(start[1],end[1],n)
points = np.array([x,y]).T.reshape(-1,1,2)
segments = np.concatenate([points[:-1],points[1:]], axis=1)
lc = LineCollection(segments, cmap=cmap, linewidth=lw,zorder=15)
lc.set_array(np.linspace(0,1,n))
ax.add_collection(lc)
return ax
#%%
def boxplot_with_markers(ax,max_width, alteration='shift', msize=2.2):
hlinewidth = 0.5
@@ -290,9 +323,9 @@ def plot_rheo_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration=
ax.set_xlabel('$g$/$g_{WT}$')
for mod in model_names:
if mod == model_name_dict[model]:
ax.plot(df['alteration'], df[mod], color=clr_dict[mod], alpha=1, zorder=10, linewidth=2)
ax.plot(df['alteration'], df[mod], color=clr_dict[mod], alpha=1, zorder=10, linewidth=2)
else:
ax.plot(df['alteration'], df[mod], color=clr_dict[mod], alpha=1, zorder=1, linewidth=1)
ax.plot(df['alteration'], df[mod], color=clr_dict[mod], alpha=0.5, zorder=1, linewidth=1)
ax.set_ylabel('$\Delta$ Rheobase (nA)', labelpad=0)
x = df['alteration']
@@ -300,6 +333,25 @@ def plot_rheo_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration=
ax.set_xlim(x.min(), x.max())
ax.set_ylim(df[model_names].min().min(), df[model_names].max().max())
# x axis color gradient
cvals = [-2., 2]
colors = ['lightgrey', 'k']
norm = plt.Normalize(min(cvals), max(cvals))
tuples = list(zip(map(norm, cvals), colors))
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples)
(xstart, xend) = ax.get_xlim()
(ystart, yend) = ax.get_ylim()
print(ystart, yend)
start = (xstart, ystart*1.0)
end = (xend, ystart*1.0)
ax = gradientaxis(ax, start, end, cmap, n=100,lw=2)
ax.spines['bottom'].set_visible(False)
# ax.set_ylim(ystart, yend)
#xlabel tick colors
# my_colors = ['lightgrey', 'grey', 'k']
# for ticklabel, tickcolor in zip(ax.get_xticklabels(), my_colors):
# ticklabel.set_color(tickcolor)
return ax
def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color2='dodgerblue'):
@@ -330,6 +382,27 @@ def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color
for i in newdf.index:
ax.plot(json.loads(newdf.loc[i, 'I']), json.loads(newdf.loc[i, 'F']), color=colors[c])
c += 1
# colors2 = [colors[10, :], 'k']
# norm2 = plt.Normalize(min(cvals), max(cvals))
# tuples2 = list(zip(map(norm2, cvals), colors2))
# cmap2 = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples2)
#
# colors3 = [colors[11, :], 'lightgrey']
# norm3 = plt.Normalize(min(cvals), max(cvals))
# tuples3 = list(zip(map(norm3, cvals), colors3))
# cmap3 = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples3)
#
# start = (1.1, json.loads(newdf.loc[10, 'F'])[-1])
# end = (1.1, json.loads(newdf.loc[20, 'F'])[-1])#-json.loads(newdf.loc[20, 'F'])[-1]*0.1)
# ax = rainbowarrow(ax, start, end, cmap2, n=50, lw=1)
# ax.text(1.15, json.loads(newdf.loc[20, 'F'])[-1], '$+ \Delta V$', fontsize=4, color='k')
#
# start = (1.1, json.loads(newdf.loc[10, 'F'])[-1])
# end = (1.1, json.loads(newdf.loc[0, 'F'])[-1])#-json.loads(newdf.loc[0, 'F'])[-1]*0.1)
# ax = rainbowarrow(ax, start, end, cmap3, n=50, lw=1)
# ax.text(1.15, json.loads(newdf.loc[0, 'F'])[-1], '$- \Delta V$', fontsize=4, color='lightgrey')
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Current [nA]')
ax.set_title(model, x=0.2, y=1.025)
@@ -424,5 +497,41 @@ ax2.text(-0.075, 1.35, string.ascii_uppercase[8], transform=ax2.transAxes, size=
# save
fig.set_size_inches(cm2inch(20.75,12))
fig.savefig('./Figures/rheobase_correlation.png', dpi=fig.dpi) #bbox_inches='tight', dpi=fig.dpi # eps # pdf
fig.savefig('./Figures/rheobase_correlation.pdf', dpi=fig.dpi)
# fig.savefig('./Figures/rheobase_correlation.png', dpi=fig.dpi) #bbox_inches='tight', dpi=fig.dpi # eps # pdf
plt.show()
#%%
# fig, axs = plt.subplots(1,2)
# axs[0] = plot_fI(axs[0] , model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', type='shift', alt='s', color1='lightgrey', color2='k')
# plt.show()
#%%
#
#
# cvals = [-2., 2]
# colors = ['lightgrey', 'k']
#
# norm = plt.Normalize(min(cvals), max(cvals))
# tuples = list(zip(map(norm, cvals), colors))
# cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples)
# colors = cmap(np.linspace(0, 1, 22))
#
# colors2 = [colors[10,:], 'k']
# norm2 = plt.Normalize(min(cvals), max(cvals))
# tuples2 = list(zip(map(norm2, cvals), colors2))
# cmap2 = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples2)
#
# colors3 = [colors[11,:], 'lightgrey']
# norm3 = plt.Normalize(min(cvals), max(cvals))
# tuples3 = list(zip(map(norm3, cvals), colors3))
# cmap3 = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples3)
#
# fig, axs = plt.subplots(1,2)
# start = (0,0)
# end = (1,1)
# axs[0] = rainbowarrow(axs[0], start, end, cmap2, n=50,lw=3)
# start = (0,0)
# end = (-1,-1)
# axs[0] = rainbowarrow(axs[0], start, end, cmap3, n=50,lw=3)
# plt.show()

View File

@@ -160,7 +160,7 @@ def mutation_plot(ax, model='RS_pramidal'):
ax.plot(rheo.loc['V404I', model_names[mod]]*1000, AUC.loc['V404I', model_names[mod]]*100, linestyle='',
markeredgecolor=mut_col[3], markerfacecolor=mut_col[5], marker=Marker_dict[model_display_names[mod]],markersize=4)
ax.set_title(model_display_names[mod], pad=14)
ax.set_xlabel('$\Delta$ Rheobase (pA)')
ax.set_xlabel('$\Delta$ Rheobase [pA]')
ax.set_ylabel('Normalized $\Delta$AUC (%)')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
@@ -241,6 +241,7 @@ axr1.text(-0.77, 1.1, string.ascii_uppercase[j+1], transform=axr1.transAxes, siz
# save
fig.set_size_inches(cm2inch(22.2,15))
# fig.savefig('./Figures/simulation_model_comparison.pdf', dpi=fig.dpi) #eps
fig.savefig('./Figures/simulation_model_comparison.png', dpi=fig.dpi) #eps
plt.show()