changes from meeting 06.03.2023; changed cell-type to neuron-type throughout, K to Kd throughout (including Fig 3 and 4), added references

This commit is contained in:
nkoch1
2023-03-06 14:22:34 -05:00
parent 6549cc0745
commit 275fb4062a
7 changed files with 507 additions and 317 deletions

View File

@@ -1,38 +1,48 @@
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 3 19:52:04 2021
Script to plot AUC correlations - Figure 3
@author: nils
"""
__author__ = "Nils A. Koch"
__copyright__ = "Copyright 2022, Nils A. Koch"
__license__ = "MIT"
import pandas as pd
import numpy as np
from numpy import ndarray
import string
import textwrap
import json
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import matplotlib.transforms
import matplotlib.path
import matplotlib.colors
from matplotlib import ticker
from matplotlib.ticker import NullFormatter
from Figures.plotstyle import boxplot_style
from matplotlib.axes._axes import Axes
from matplotlib.markers import MarkerStyle
from matplotlib.collections import LineCollection
from Figures.plotstyle import corr_style
def cm2inch(*tupl):
'''
convert cm to inch for plots size tuple
'''
inch = 2.54
if isinstance(tupl[0], tuple):
return tuple(i/inch for i in tupl[0])
else:
return tuple(i/inch for i in tupl)
#%% ##################### From https://stackoverflow.com/questions/52878845/swarmplot-with-hue-affecting-marker-beyond-color ##
# to change marker types in seaborn swarmplot
import seaborn as sns
import matplotlib.pyplot as plt
############## Begin hack ##############
from matplotlib.axes._axes import Axes
from matplotlib.markers import MarkerStyle
from numpy import ndarray
#%% Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
def GetColor2Marker(markers):
'''
Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
'''
colorslist = ['#40A787', # cyan'#
'#F0D730', # yellow
'#C02717', # red
@@ -52,6 +62,9 @@ def GetColor2Marker(markers):
return dict(zip(mkcolors,markers))
def fixlegend(ax,markers,markersize=3,**kwargs):
'''
Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
'''
# Fix Legend
legtitle = ax.get_legend().get_title().get_text()
_,l = ax.get_legend_handles_labels()
@@ -79,6 +92,9 @@ def fixlegend(ax,markers,markersize=3,**kwargs):
old_scatter = Axes.scatter
def new_scatter(self, *args, **kwargs):
'''
Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
'''
colors = kwargs.get("c", None)
co2mk = kwargs.pop("co2mk",None)
FinalCollection = old_scatter(self, *args, **kwargs)
@@ -92,16 +108,32 @@ def new_scatter(self, *args, **kwargs):
FinalCollection.set_paths(paths)
return FinalCollection
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
'''
add color gradient to axis
Parameters
----------
ax : matplotlib axis
axis to apply gradient to
start : tuple
start coordinates on axis
end : tuple
end coordinates on axis
cmap : colormap
colormap for gradient
n : int
number of segments in gradient
lw : float
width of axis line
Returns
-------
ax : matplotlib axis
updated axis with gradient
'''
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)
@@ -110,15 +142,26 @@ def gradientaxis(ax, start, end, cmap, n=100,lw=1):
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):
def corr_with_markers(ax,max_width, alteration='shift', msize=3):
'''
Plot Model Correlation as markers
Parameters
----------
ax : matplotlib axis
axis to plot on
max_width :
maximum width of label text
alteration : string
'shift', 'slope' or 'g'
msize : float
marker size
'''
hlinewidth = 0.5
model_names = ['RS pyramidal','RS inhibitory','FS',
'RS pyramidal +$K_V1.1$','RS inhibitory +$K_V1.1$',
'FS +$K_V1.1$','Cb stellate','Cb stellate +$K_V1.1$',
'Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$',
'STN $\Delta$$K_V1.1$']
model_names = ['RS pyramidal','RS inhibitory','FS', 'RS pyramidal +$K_V1.1$','RS inhibitory +$K_V1.1$',
'FS +$K_V1.1$','Cb stellate','Cb stellate +$K_V1.1$', 'Cb stellate $\Delta$$K_V1.1$','STN',
'STN +$K_V1.1$', 'STN $\Delta$$K_V1.1$']
colorslist = ['#007030', # dark green
'#F0D730', # yellow
@@ -135,11 +178,12 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=3):
]
import matplotlib.colors
colors = [matplotlib.colors.to_rgb(c) for c in colorslist]
clr_dict = {}
for m in range(len(model_names)):
clr_dict[model_names[m]] = colors[m]
print(colors)
print(clr_dict)
Markers = ["o", "o", "o", "^", "^", "^", "D", "D", "D", "s", "s", "s"]
if alteration=='shift':
i = 2 # Kd act
@@ -155,7 +199,7 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=3):
ax.plot([lim[0], lim[1]], [1, 1], ':k',linewidth=hlinewidth)
ax.plot([lim[0], lim[1]], [-1, -1], ':k',linewidth=hlinewidth)
ax.set_title("Shift ($\Delta V_{1/2}$)", y=1.05)
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'K \nactivation', '$K_V1.1$ \nactivation',
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'Kd \nactivation', '$K_V1.1$ \nactivation',
'$K_V1.1$ \ninactivation', 'A \nactivation', 'A \ninactivation'])
elif alteration=='slope':
i = 3 # Kv1.1 act
@@ -173,7 +217,7 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=3):
ax.plot([lim[0], lim[1]], [1, 1], ':k',linewidth=hlinewidth)
ax.plot([lim[0], lim[1]], [-1, -1], ':k',linewidth=hlinewidth)
ax.set_title("Slope (k)", y=1.05)
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'K \nactivation', '$K_V1.1$ \nactivation',
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'Kd \nactivation', '$K_V1.1$ \nactivation',
'$K_V1.1$ \ninactivation', 'A \nactivation', 'A \ninactivation'])
elif alteration=='g':
i = 1 # Kd
@@ -192,7 +236,8 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=3):
ax.plot([lim[0], lim[1]], [-1, -1], ':k',linewidth=hlinewidth)
# Tweak the visual presentation
ax.set_title("Conductance (g)", y=1.05)
ax.set_xticklabels(textwrap.fill(x.get_text(), max_width) for x in ax.get_xticklabels())
# ax.set_xticklabels(textwrap.fill(x.get_text(), max_width) for x in ax.get_xticklabels())
ax.set_xticklabels(['Na', 'Kd', '$K_V1.1$', 'A', 'Leak'])
else:
print('Please chose "shift", "slope" or "g"')
ax.get_legend().remove()
@@ -202,19 +247,34 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=3):
def model_legend(ax, marker_s_leg, pos, ncol):
colorslist = [ '#40A787', # cyan'#
'#F0D730', # yellow
'#C02717', # red
'#007030', # dark green
'#AAB71B', # lightgreen
'#008797', # light blue
'#F78017', # orange
'#478010', # green
'#53379B', # purple
'#2060A7', # blue
'#873770', # magenta
'#D03050' # pink
]
'''
plot model legend on axis
Parameters
----------
ax : matplotlib axis
axis to plot legend on
marker_s_leg : int
marker size in legend
pos : tuple
position in axis
ncol : int
number of columns in legend
'''
colorslist = ['#007030', # dark green
'#F0D730', # yellow
'#C02717', # red
'#478010', # green
'#AAB71B', # lightgreen
'#F78017', # orange
'#40A787', # cyan'#
'#008797', # light blue
'#2060A7', # blue
'#D03050', # pink
'#53379B', # purple
'#873770', # magenta
]
import matplotlib.colors
colors = [matplotlib.colors.to_rgb(c) for c in colorslist]
model_pos = {'Cb stellate':0, 'RS Inhibitory':1, 'FS':2, 'RS Pyramidal':3,
@@ -224,38 +284,44 @@ def model_legend(ax, marker_s_leg, pos, ncol):
'Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':9,
'STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':10, 'STN':11}
Markers = ["o", "o", "o", "^", "^", "^", "D", "D", "D", "s", "s", "s"]
RS_p = mlines.Line2D([], [], color=colors[model_pos['RS Pyramidal']], marker=Markers[model_pos['RS Pyramidal']], markersize=marker_s_leg, linestyle='None',
label='RS pyramidal')
RS_i = mlines.Line2D([], [], color=colors[model_pos['RS Inhibitory']], marker=Markers[model_pos['RS Inhibitory']], markersize=marker_s_leg, linestyle='None',
label='RS inhibitory')
FS = mlines.Line2D([], [], color=colors[model_pos['FS']], marker=Markers[model_pos['FS']], markersize=marker_s_leg, linestyle='None', label='FS')
RS_p_Kv = mlines.Line2D([], [], color=colors[model_pos['RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
RS_i_Kv = mlines.Line2D([], [], color=colors[model_pos['RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
FS_Kv = mlines.Line2D([], [], color=colors[model_pos['Cb stellate']], marker=Markers[model_pos['Cb stellate']], markersize=marker_s_leg, linestyle='None', label='FS +$K_V1.1$')
Cb = mlines.Line2D([], [], color=colors[8], marker=Markers[8], markersize=marker_s_leg, linestyle='None',
label='Cb stellate')
Cb_pl = mlines.Line2D([], [], color=colors[model_pos['Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
Cb_sw = mlines.Line2D([], [], color=colors[model_pos['Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
STN = mlines.Line2D([], [], color=colors[model_pos['STN']], marker=Markers[model_pos['STN']], markersize=marker_s_leg, linestyle='None', label='STN')
STN_pl = mlines.Line2D([], [], color=colors[model_pos['STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
STN_sw = mlines.Line2D([], [], color=colors[model_pos['STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
ax.legend(handles=[RS_p, RS_i, FS, RS_p_Kv, RS_i_Kv, FS_Kv, Cb, Cb_pl, Cb_sw, STN, STN_pl, STN_sw], loc='center',
bbox_to_anchor=pos, ncol=ncol, frameon=False)
def plot_AUC_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration='shift'):
RS_p = mlines.Line2D([], [], color='#007030', marker="^", markersize=marker_s_leg, linestyle='None', label='Model D')
RS_i = mlines.Line2D([], [], color='#F0D730', marker="o", markersize=marker_s_leg, linestyle='None', label='Model B')
FS = mlines.Line2D([], [], color='#C02717', marker="o", markersize=marker_s_leg, linestyle='None', label='Model C')
RS_p_Kv = mlines.Line2D([], [], color='#478010', marker="D", markersize=marker_s_leg, linestyle='None', label='Model H')
RS_i_Kv = mlines.Line2D([], [], color='#AAB71B', marker="^", markersize=marker_s_leg, linestyle='None', label='Model E')
FS_Kv = mlines.Line2D([], [], color='#F78017', marker="D", markersize=marker_s_leg, linestyle='None', label='Model G')
Cb = mlines.Line2D([], [], color='#40A787', marker="o", markersize=marker_s_leg, linestyle='None', label='Model A')
Cb_pl = mlines.Line2D([], [], color='#008797', marker="^", markersize=marker_s_leg, linestyle='None', label='Model F')
Cb_sw = mlines.Line2D([], [], color='#2060A7', marker="s", markersize=marker_s_leg, linestyle='None', label='Model J')
STN = mlines.Line2D([], [], color='#D03050', marker="s", markersize=marker_s_leg, linestyle='None', label='Model L')
STN_pl = mlines.Line2D([], [], color='#53379B', marker="D", markersize=marker_s_leg, linestyle='None', label='Model I')
STN_sw = mlines.Line2D([], [], color='#873770', marker="s", markersize=marker_s_leg, linestyle='None', label='Model K')
ax.legend(handles=[Cb, RS_i, FS, RS_p, RS_i_Kv, Cb_pl, FS_Kv, RS_p_Kv, STN_pl, Cb_sw, STN_sw, STN], loc='center',
bbox_to_anchor=pos, ncol=ncol, frameon=False)
def plot_AUC_alt(ax, model='FS', alteration='shift'):
'''
plot the AUC across an alteration for all models with one emphasized
Parameters
----------
ax : matplotlib axis
axis to plot on
model : string
model to emphasize with thicker line
alteration : string
'shift', 'slope' or 'g'
Returns
-------
ax : matplotlib axis
updated axis with plot data
'''
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
model_names = ['RS Pyramidal','RS Inhibitory','FS',
'RS Pyramidal +$K_V1.1$','RS Inhibitory +$K_V1.1$',
'FS +$K_V1.1$','Cb stellate','Cb stellate +$K_V1.1$',
'Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$',
'STN $\Delta$$K_V1.1$']
model_names = ['RS Pyramidal','RS Inhibitory','FS', 'RS Pyramidal +$K_V1.1$','RS Inhibitory +$K_V1.1$',
'FS +$K_V1.1$','Cb stellate','Cb stellate +$K_V1.1$', 'Cb stellate $\Delta$$K_V1.1$','STN',
'STN +$K_V1.1$', 'STN $\Delta$$K_V1.1$']
model_name_dict = {'RS Pyramidal': 'RS Pyramidal',
'RS Inhibitory': 'RS Inhibitory',
@@ -337,6 +403,29 @@ def plot_AUC_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration='
return ax
def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color2='dodgerblue'):
'''
plot fI curves for a model across an alteration in current parameters
Parameters
----------
ax : matplotlib axis
axis to plot on
model : string
model to plot
type : string
type of alteration: 'shift', 'slope', or 'g'
alt : string
model parameter that is altered
color1 : string
color at start of gradient
color2 : string
color at end of gradient
Returns
-------
ax : matplotlib axis
updated axis with plot data
'''
model_save_name = {'RS Pyramidal': 'RS_pyr_posp',
'RS Inhibitory': 'RS_inhib_posp',
'FS': 'FS_posp',
@@ -366,7 +455,12 @@ def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color
c += 1
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Current [nA]')
ax.set_title(model, x=0.2, y=1.0)
if model == 'FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':
ax.set_title("Model G", x=0.2, y=1.0)
elif model == 'STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':
ax.set_title("Model I", x=0.2, y=1.0)
else:
ax.set_title("", x=0.2, y=1.0)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
L = ax.get_ylim()
@@ -375,7 +469,7 @@ def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color
#%%
boxplot_style()
corr_style()
color_dict = {'Cb stellate': '#40A787', # cyan'#
'RS Inhibitory': '#F0D730', # yellow
'FS': '#C02717', # red
@@ -443,19 +537,19 @@ rec = ax2_fI.add_patch(rec)
rec.set_clip_on(False)
# plot boxplots
boxplot_with_markers(ax0,max_width, alteration='shift')
boxplot_with_markers(ax1,max_width, alteration='slope')
boxplot_with_markers(ax2,max_width, alteration='g')
corr_with_markers(ax0,max_width, alteration='shift')
corr_with_markers(ax1,max_width, alteration='slope')
corr_with_markers(ax2,max_width, alteration='g')
# plot legend
pos = (0.225, -0.9)
ncol = 5
ncol = 6
model_legend(ax2, marker_s_leg, pos, ncol)
# plot examples
plot_AUC_alt(ax0_ex,model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', color1='lightgrey', color2='k', alteration='shift')
plot_AUC_alt(ax1_ex,model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', color1='lightgrey', color2='k',alteration='slope')
plot_AUC_alt(ax2_ex, model='STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', color1='lightgrey', color2='k', alteration='g')
plot_AUC_alt(ax0_ex,model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', alteration='shift')
plot_AUC_alt(ax1_ex,model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', alteration='slope')
plot_AUC_alt(ax2_ex, model='STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', alteration='g')
# label subplots with letters
ax0_fI.text(-0.875, 1.35, string.ascii_uppercase[0], transform=ax0_fI.transAxes, size=10, weight='bold')
@@ -472,6 +566,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.pdf', dpi=fig.dpi) #pdf #eps
# fig.savefig('./Figures/AUC_correlation.png', dpi=fig.dpi) #pdf #eps
fig.savefig('./Figures/AUC_correlation.pdf', dpi=fig.dpi)
# fig.savefig('./Figures/AUC_correlation.png', dpi=fig.dpi) #png
plt.show()

View File

@@ -1,22 +1,37 @@
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 3 19:52:04 2021
Script to plot rheobase correlations - Figure 4
@author: nils
"""
__author__ = "Nils A. Koch"
__copyright__ = "Copyright 2022, Nils A. Koch"
__license__ = "MIT"
import pandas as pd
import numpy as np
from numpy import ndarray
import string
import textwrap
import json
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import matplotlib.transforms
import matplotlib.path
import matplotlib.colors
from matplotlib import ticker
from matplotlib.ticker import NullFormatter
from Figures.plotstyle import boxplot_style
from matplotlib.axes._axes import Axes
from matplotlib.markers import MarkerStyle
from matplotlib.collections import LineCollection
from Figures.plotstyle import corr_style
def cm2inch(*tupl):
'''
convert cm to inch for plots size tuple
'''
inch = 2.54
if isinstance(tupl[0], tuple):
return tuple(i/inch for i in tupl[0])
@@ -24,16 +39,10 @@ def cm2inch(*tupl):
return tuple(i/inch for i in tupl)
#%% ##################### From https://stackoverflow.com/questions/52878845/swarmplot-with-hue-affecting-marker-beyond-color ##
# to change marker types in seaborn swarmplot
import seaborn as sns
import matplotlib.pyplot as plt
############## Begin hack ##############
from matplotlib.axes._axes import Axes
from matplotlib.markers import MarkerStyle
from numpy import ndarray
def GetColor2Marker(markers):
'''
Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
'''
colorslist = ['#40A787', # cyan'#
'#F0D730', # yellow
'#C02717', # red
@@ -53,6 +62,9 @@ def GetColor2Marker(markers):
return dict(zip(mkcolors,markers))
def fixlegend(ax,markers,markersize=3,**kwargs):
'''
Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
'''
# Fix Legend
legtitle = ax.get_legend().get_title().get_text()
_,l = ax.get_legend_handles_labels()
@@ -80,6 +92,9 @@ def fixlegend(ax,markers,markersize=3,**kwargs):
old_scatter = Axes.scatter
def new_scatter(self, *args, **kwargs):
'''
Modified from https://stackoverflow.com/a/52935294 (ImportanceOfBeingErnest and Miguel) under CC BY-SA 4.0 license
'''
colors = kwargs.get("c", None)
co2mk = kwargs.pop("co2mk",None)
FinalCollection = old_scatter(self, *args, **kwargs)
@@ -93,33 +108,32 @@ def new_scatter(self, *args, **kwargs):
FinalCollection.set_paths(paths)
return FinalCollection
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):
'''
add color gradient to axis
Parameters
----------
ax : matplotlib axis
axis to apply gradient to
start : tuple
start coordinates on axis
end : tuple
end coordinates on axis
cmap : colormap
colormap for gradient
n : int
number of segments in gradient
lw : float
width of axis line
Returns
-------
ax : matplotlib axis
updated axis with gradient
'''
# Arrow shaft: LineCollection
x = np.linspace(start[0],end[0],n)
y = np.linspace(start[1],end[1],n)
@@ -129,8 +143,22 @@ def gradientaxis(ax, start, end, cmap, n=100,lw=1):
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):
def corr_with_markers(ax,max_width, alteration='shift', msize=2.2):
'''
Plot Model Correlation as markers
Parameters
----------
ax : matplotlib axis
axis to plot on
max_width :
maximum width of label text
alteration : string
'shift', 'slope' or 'g'
msize : float
marker size
'''
hlinewidth = 0.5
model_names = ['RS pyramidal','RS inhibitory','FS',
'RS pyramidal +$K_V1.1$','RS inhibitory +$K_V1.1$',
@@ -157,8 +185,6 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=2.2):
clr_dict = {}
for m in range(len(model_names)):
clr_dict[model_names[m]] = colors[m]
print(colors)
print(clr_dict)
Markers = ["o", "o", "o", "^", "^", "^", "D", "D", "D", "s", "s", "s"]
if alteration=='shift':
i = 3 # Kv1.1 act
@@ -174,7 +200,7 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=2.2):
ax.plot([lim[0], lim[1]], [1, 1], ':k',linewidth=hlinewidth)
ax.plot([lim[0], lim[1]], [-1, -1], ':k',linewidth=hlinewidth)
ax.set_title("Shift ($\Delta V_{1/2}$)", y=1.05)
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'K \nactivation', '$K_V1.1$ \nactivation',
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'Kd \nactivation', '$K_V1.1$ \nactivation',
'$K_V1.1$ \ninactivation', 'A \nactivation', 'A \ninactivation'])
elif alteration=='slope':
i = 4 # Kv1.1 inact
@@ -192,7 +218,7 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=2.2):
ax.plot([lim[0], lim[1]], [1, 1], ':k',linewidth=hlinewidth)
ax.plot([lim[0], lim[1]], [-1, -1], ':k',linewidth=hlinewidth)
ax.set_title("Slope (k)", y=1.05)
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'K \nactivation', '$K_V1.1$ \nactivation',
ax.set_xticklabels(['Na \nactivation', 'Na \ninactivation', 'Kd \nactivation', '$K_V1.1$ \nactivation',
'$K_V1.1$ \ninactivation', 'A \nactivation', 'A \ninactivation'])
elif alteration=='g':
i = 4 # Leak
@@ -209,7 +235,8 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=2.2):
ax.plot([lim[0], lim[1]], [1, 1], ':k',linewidth=hlinewidth)
ax.plot([lim[0], lim[1]], [-1, -1], ':k',linewidth=hlinewidth)
ax.set_title("Conductance (g)", y=1.05)
ax.set_xticklabels(textwrap.fill(x.get_text(), max_width) for x in ax.get_xticklabels())
# ax.set_xticklabels(textwrap.fill(x.get_text(), max_width) for x in ax.get_xticklabels())
ax.set_xticklabels(['Na', 'Kd', '$K_V1.1$', 'A', 'Leak'])
else:
print('Please chose "shift", "slope" or "g"')
ax.get_legend().remove()
@@ -219,78 +246,88 @@ def boxplot_with_markers(ax,max_width, alteration='shift', msize=2.2):
def model_legend(ax, marker_s_leg, pos, ncol):
# colorslist = [ '#40A787', # cyan'#
# '#F0D730', # yellow
# '#C02717', # red
# '#007030', # dark green
# '#AAB71B', # lightgreen
# '#008797', # light blue
# '#F78017', # orange
# '#478010', # green
# '#53379B', # purple
# '#2060A7', # blue
# '#873770', # magenta
# '#D03050' # pink
# ]
# import matplotlib.colors
# colors = [matplotlib.colors.to_rgb(c) for c in colorslist]
model_pos = {'Cb stellate':0, 'RS Inhibitory':1, 'FS':2, 'RS Pyramidal':3,
'RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':4,
'Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':5, 'FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':6,
'RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':7, 'STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':8,
'Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':9,
'STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':10, 'STN':11}
'''
plot model legend on axis
Parameters
----------
ax : matplotlib axis
axis to plot legend on
marker_s_leg : int
marker size in legend
pos : tuple
position in axis
ncol : int
number of columns in legend
# model_pos = {'Cb stellate': 0, 'RS Inhibitory': 1, 'FS': 2, 'RS Pyramidal': 3,
# 'RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 4,
# 'Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 5,
# 'FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 6,
# 'RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 7,
# 'STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 8,
# 'Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 9,
# 'STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$': 10, 'STN': 11}
colorslist = ['#007030', # dark green
'#F0D730', # yellow
'#C02717', # red
'#478010', # green
'#AAB71B', # lightgreen
'#F78017', # orange
'#40A787', # cyan'#
'#008797', # light blue
'#2060A7', # blue
'#D03050', # pink
'#53379B', # purple
'#873770', # magenta
]
'''
colorslist = [ '#40A787', # cyan'#
'#F0D730', # yellow
'#C02717', # red
'#007030', # dark green
'#AAB71B', # lightgreen
'#008797', # light blue
'#F78017', # orange
'#478010', # green
'#53379B', # purple
'#2060A7', # blue
'#873770', # magenta
'#D03050' # pink
]
model_names = ['RS pyramidal', 'RS inhibitory', 'FS',
'RS pyramidal +$K_V1.1$', 'RS inhibitory +$K_V1.1$',
'FS +$K_V1.1$', 'Cb stellate', 'Cb stellate +$K_V1.1$',
'Cb stellate $\Delta$$K_V1.1$', 'STN', 'STN +$K_V1.1$',
'STN $\Delta$$K_V1.1$']
import matplotlib.colors
colors = [matplotlib.colors.to_rgb(c) for c in colorslist]
clr_dict = {}
for m in range(len(model_names)):
clr_dict[model_names[m]] = colors[m]
import matplotlib.colors
colors = [matplotlib.colors.to_rgb(c) for c in colorslist]
Markers = ["o", "o", "o", "^", "^", "^", "D", "D", "D", "s", "s", "s"]
RS_p = mlines.Line2D([], [], color=colors[model_pos['RS Pyramidal']], marker=Markers[model_pos['RS Pyramidal']], markersize=marker_s_leg, linestyle='None',
label='RS pyramidal')
RS_i = mlines.Line2D([], [], color=colors[model_pos['RS Inhibitory']], marker=Markers[model_pos['RS Inhibitory']], markersize=marker_s_leg, linestyle='None',
label='RS inhibitory')
FS = mlines.Line2D([], [], color=colors[model_pos['FS']], marker=Markers[model_pos['FS']], markersize=marker_s_leg, linestyle='None', label='FS')
RS_p_Kv = mlines.Line2D([], [], color=colors[model_pos['RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
RS_i_Kv = mlines.Line2D([], [], color=colors[model_pos['RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
FS_Kv = mlines.Line2D([], [], color=colors[model_pos['Cb stellate']], marker=Markers[model_pos['Cb stellate']], markersize=marker_s_leg, linestyle='None', label='FS +$K_V1.1$')
Cb = mlines.Line2D([], [], color=colors[8], marker=Markers[8], markersize=marker_s_leg, linestyle='None',
label='Cb stellate')
Cb_pl = mlines.Line2D([], [], color=colors[model_pos['Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
Cb_sw = mlines.Line2D([], [], color=colors[model_pos['Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
STN = mlines.Line2D([], [], color=colors[model_pos['STN']], marker=Markers[model_pos['STN']], markersize=marker_s_leg, linestyle='None', label='STN')
STN_pl = mlines.Line2D([], [], color=colors[model_pos['STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
STN_sw = mlines.Line2D([], [], color=colors[model_pos['STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], marker=Markers[model_pos['STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$']], markersize=marker_s_leg, linestyle='None',
label='STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$')
ax.legend(handles=[RS_p, RS_i, FS, RS_p_Kv, RS_i_Kv, FS_Kv, Cb, Cb_pl, Cb_sw, STN, STN_pl, STN_sw], loc='center',
model_pos = {'RS Pyramidal':0, 'RS Inhibitory':1, 'FS':2,
'RS Pyramidal +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':3, 'RS Inhibitory +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':4,
'FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':5, 'Cb stellate':6, 'Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':7,
'Cb stellate $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':8, 'STN':9, 'STN +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':10,
'STN $\Delta$$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':11}
RS_p = mlines.Line2D([], [], color='#007030', marker="^", markersize=marker_s_leg, linestyle='None', label='Model D')
RS_i = mlines.Line2D([], [], color='#F0D730', marker="o", markersize=marker_s_leg, linestyle='None', label='Model B')
FS = mlines.Line2D([], [], color='#C02717', marker="o", markersize=marker_s_leg, linestyle='None', label='Model C')
RS_p_Kv = mlines.Line2D([], [], color='#478010', marker="D", markersize=marker_s_leg, linestyle='None', label='Model H')
RS_i_Kv = mlines.Line2D([], [], color='#AAB71B', marker="^", markersize=marker_s_leg, linestyle='None', label='Model E')
FS_Kv = mlines.Line2D([], [], color='#F78017', marker="D", markersize=marker_s_leg, linestyle='None', label='Model G')
Cb = mlines.Line2D([], [], color='#40A787', marker="o", markersize=marker_s_leg, linestyle='None', label='Model A')
Cb_pl = mlines.Line2D([], [], color='#008797', marker="^", markersize=marker_s_leg, linestyle='None', label='Model F')
Cb_sw = mlines.Line2D([], [], color='#2060A7', marker="s", markersize=marker_s_leg, linestyle='None', label='Model J')
STN = mlines.Line2D([], [], color='#D03050', marker="s", markersize=marker_s_leg, linestyle='None', label='Model L')
STN_pl = mlines.Line2D([], [], color='#53379B', marker="D", markersize=marker_s_leg, linestyle='None', label='Model I')
STN_sw = mlines.Line2D([], [], color='#873770', marker="s", markersize=marker_s_leg, linestyle='None', label='Model K')
ax.legend(handles=[Cb, RS_i, FS, RS_p, RS_i_Kv, Cb_pl, FS_Kv, RS_p_Kv, STN_pl, Cb_sw, STN_sw, STN], loc='center',
bbox_to_anchor=pos, ncol=ncol, frameon=False)
def plot_rheo_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration='shift'):
def plot_rheo_alt(ax, model='FS', alteration='shift'):
'''
plot the rheobase across an alteration for all models with one emphasized
Parameters
----------
ax : matplotlib axis
axis to plot on
model : string
model to emphasize with thicker line
alteration : string
'shift', 'slope' or 'g'
Returns
-------
ax : matplotlib axis
updated axis with plot data
'''
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
model_names = ['RS Pyramidal','RS Inhibitory','FS',
@@ -373,15 +410,32 @@ def plot_rheo_alt(ax, model='FS', color1='red', color2='dodgerblue', alteration=
end = (xend, ystart*1.0)
ax = gradientaxis(ax, start, end, cmap, n=200,lw=4)
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'):
'''
plot fI curves for a model across an alteration in current parameters
Parameters
----------
ax : matplotlib axis
axis to plot on
model : string
model to plot
type : string
type of alteration: 'shift', 'slope', or 'g'
alt : string
model parameter that is altered
color1 : string
color at start of gradient
color2 : string
color at end of gradient
Returns
-------
ax : matplotlib axis
updated axis with plot data
'''
model_save_name = {'RS Pyramidal': 'RS_pyr_posp',
'RS Inhibitory': 'RS_inhib_posp',
'FS': 'FS_posp',
@@ -409,30 +463,16 @@ 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)
if model == 'FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':
ax.set_title("Model G", x=0.2, y=1.0)
elif model == 'Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$':
ax.set_title("Model F", x=0.2, y=1.0)
elif model == 'Cb stellate':
ax.set_title("Model A", x=0.2, y=1.0)
else:
ax.set_title("", x=0.2, y=1.0)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
L = ax.get_ylim()
@@ -441,7 +481,7 @@ def plot_fI(ax, model='RS Pyramidal', type='shift', alt='m', color1='red', color
#%%
boxplot_style()
corr_style()
color_dict = {'Cb stellate': '#40A787', # cyan'#
'RS Inhibitory': '#F0D730', # yellow
'FS': '#C02717', # red
@@ -495,19 +535,19 @@ rec.set_clip_on(False)
# plot boxplots
boxplot_with_markers(ax0,max_width, alteration='shift')
boxplot_with_markers(ax1,max_width, alteration='slope')
boxplot_with_markers(ax2,max_width, alteration='g')
corr_with_markers(ax0,max_width, alteration='shift')
corr_with_markers(ax1,max_width, alteration='slope')
corr_with_markers(ax2,max_width, alteration='g')
# plot legend
pos = (0.225, -0.9)
ncol = 5
ncol = 6
model_legend(ax2, marker_s_leg, pos, ncol)
# plot rheo across model for example alteration
plot_rheo_alt(ax0_ex,model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', color1='lightgrey', color2='k', alteration='shift')
plot_rheo_alt(ax1_ex,model='Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', color1='lightgrey', color2='k',alteration='slope')
plot_rheo_alt(ax2_ex, model='Cb stellate', color1='lightgrey', color2='k', alteration='g')
plot_rheo_alt(ax0_ex,model='FS +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', alteration='shift')
plot_rheo_alt(ax1_ex,model='Cb stellate +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$', alteration='slope')
plot_rheo_alt(ax2_ex, model='Cb stellate', alteration='g')
# label subplots with letters
ax0_fI.text(-0.875, 1.35, string.ascii_uppercase[0], transform=ax0_fI.transAxes, size=10, weight='bold')
@@ -525,40 +565,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/rheobase_correlation.pdf', dpi=fig.dpi)
# fig.savefig('./Figures/rheobase_correlation.png', dpi=fig.dpi) #bbox_inches='tight', dpi=fig.dpi # eps # pdf
# fig.savefig('./Figures/rheobase_correlation.png', dpi=fig.dpi)
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()