Skip to content

Commit 9130dd2

Browse files
committed
stylized vectors figure
1 parent 48e3e99 commit 9130dd2

1 file changed

Lines changed: 69 additions & 33 deletions

File tree

figures/kCSD_properties/figure_vectors.py

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
from os.path import expanduser
66
import numpy as np
77
import matplotlib.pyplot as plt
8+
from figure_properties import *
89
import matplotlib.gridspec as gridspec
10+
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
11+
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
912
import datetime
1013
import time
1114

@@ -96,9 +99,14 @@ def generate_figure(csd_profile, R, MU, TRUE_CSD_XLIMS, TOTAL_ELE, ELE_LIMS,
9699
method=method, Rs=Rs,
97100
lambdas=lambdas)
98101

99-
plt_cord = [(4, 0), (4, 2), (4, 4), (5, 0), (5, 2), (5, 4), (6, 0), (6, 2),
100-
(6, 4), (7, 0), (7, 2), (7, 4)]
101-
letters = ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N']
102+
# plt_cord = [(4, 0), (4, 2), (4, 4), (5, 0), (5, 2), (5, 4), (6, 0), (6, 2),
103+
# (6, 4), (7, 0), (7, 2), (7, 4)]
104+
plt_cord = [(3, 0), (3, 2), (3, 4),
105+
(4, 0), (4, 2), (4, 4),
106+
(5, 0), (5, 2), (5, 4),
107+
(6, 0), (6, 2), (6, 4)]
108+
109+
letters = ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N']
102110

103111
BLACK = _html(0, 0, 0)
104112
ORANGE = _html(230, 159, 0)
@@ -110,34 +118,50 @@ def generate_figure(csd_profile, R, MU, TRUE_CSD_XLIMS, TOTAL_ELE, ELE_LIMS,
110118
PURPLE = _html(204, 121, 167)
111119
colors = [BLUE, ORANGE, GREEN, PURPLE, VERMILION, SKY_BLUE, YELLOW, BLACK]
112120

113-
fig = plt.figure(figsize=(14, 13))
114-
heights = [1, 1, 1, 0.2, 1, 1, 1, 1]
121+
fig = plt.figure(figsize=(21, 18))
122+
#heights = [1, 1, 1, 0.2, 1, 1, 1, 1]
123+
heights = [1, 1, 0.2, 1, 1, 1, 1]
115124
markers = ['^', '.', '*', 'x', ',']
116-
linestyles = [':', '--', '-.', '-']
125+
#linestyles = [':', '--', '-.', '-']
126+
linestyles = ['-', '-', '-', '-']
117127
src_idx = [0, 2, 3, 8]
118128

119-
gs = gridspec.GridSpec(8, 6, height_ratios=heights)
129+
gs = gridspec.GridSpec(7, 6, height_ratios=heights, hspace=0.3, wspace=0.6)
120130

121-
ax = fig.add_subplot(gs[0:3, 0:3])
131+
ax = fig.add_subplot(gs[0:2, :])
122132
for indx, i in enumerate(src_idx):
123133
ax.plot(np.arange(1, TOTAL_ELE + 1), eigenval_M[i],
124134
linestyle=linestyles[indx], color=colors[indx],
125135
marker=markers[indx], label='M='+str(n_src_M[i]), markersize=6)
126-
ax.set_title(' ', fontsize=12)
127-
set_axis(ax, -0.05, 1.01, letter='A')
128-
ax.legend(loc='lower left')
129-
ax.set_xlabel('Number of components', fontsize=12)
130-
ax.set_ylabel('Eigenvalues', fontsize=12)
136+
#ax.set_title(' ', fontsize=12)
137+
ht, lh = ax.get_legend_handles_labels()
138+
set_axis(ax, -0.05, 1.05, letter='A')
139+
#ax.legend(loc='lower left')
140+
ax.set_xlabel('Number of components')
141+
ax.set_ylabel('Eigenvalues')
131142
ax.set_yscale('log')
132-
133-
ax = fig.add_subplot(gs[0:3, 3:])
134-
ax.plot(n_src_M, eigenval_M[:, 0], marker='s', color='k', markersize=5,
135-
linestyle=' ')
136-
ax.set_title(' ', fontsize=12)
137-
set_axis(ax, -0.05, 1.01, letter='B')
138-
ax.set_xlabel('Number of basis sources', fontsize=12)
139-
ax.set_xscale('log')
140-
ax.set_ylabel('Eigenvalues', fontsize=12)
143+
ax.set_ylim([1e-6, 1])
144+
ax.spines['right'].set_visible(False)
145+
ax.spines['top'].set_visible(False)
146+
#ax = fig.add_subplot(gs[0:3, 3:])
147+
axins = zoomed_inset_axes(ax, 7., loc=3, borderpad=3.)
148+
for indx, i in enumerate(src_idx):
149+
axins.plot(np.arange(1, TOTAL_ELE + 1), eigenval_M[i],
150+
linestyle=linestyles[indx], color=colors[indx],
151+
marker=markers[indx], label='M='+str(n_src_M[i]), markersize=6)
152+
axins.set_xlim([0.9, 1.1])
153+
axins.set_ylim([0.2, 0.4])
154+
axins.get_xaxis().set_visible(False)
155+
#axins.spines['right'].set_visible(False)
156+
#axins.spines['top'].set_visible(False)
157+
mark_inset(ax, axins, loc1=2, loc2=1, fc="none", ec="0.5")
158+
#cbaxes.plot(n_src_M, eigenval_M[:, 0], marker='s', color='k', markersize=5,
159+
# linestyle=' ')
160+
#ax.set_title(' ', fontsize=12)
161+
# set_axis(ax, -0.05, 1.01, letter='B')
162+
#ax.set_xlabel('Number of basis sources', fontsize=12)
163+
#ax.set_xscale('log')
164+
#ax.set_ylabel('Eigenvalues', fontsize=12)
141165

142166
for i in range(OBJ_M[0].k_interp_cross.shape[1]):
143167
ax = fig.add_subplot(gs[plt_cord[i][0],
@@ -147,22 +171,34 @@ def generate_figure(csd_profile, R, MU, TRUE_CSD_XLIMS, TOTAL_ELE, ELE_LIMS,
147171
eigenvec_M[j, :, i]),
148172
linestyle=linestyles[idx], color=colors[idx],
149173
label='M='+str(n_src_M[j]), lw=2)
150-
ax.set_title(f'$\\tilde{{K}}*v_{{{i+1:d}}}$', fontsize=12)
174+
#ax.set_title('$\\tilde{{K}}*v_{{{i+1:d}}}$')
151175
ax.locator_params(axis='y', nbins=3)
152-
ax.set_xlabel('Depth (mm)', fontsize=12)
153-
ax.set_ylabel('CSD (mA/mm)', fontsize=12)
176+
#ax.set_xlabel('Depth (mm)', fontsize=12)
177+
#ax.set_ylabel('CSD (mA/mm)', fontsize=12)
154178
set_axis(ax, -0.05, 1.05, letter=letters[i])
155-
156-
ht, lh = ax.get_legend_handles_labels()
157-
ax = fig.add_subplot(gs[3, :])
158-
ax.legend(ht, lh, fancybox=False, shadow=False, ncol=len(src_idx),
159-
loc='upper center', frameon=False, bbox_to_anchor=(0.5, 0.0))
160-
ax.axis('off')
161-
162-
plt.tight_layout()
179+
if i < 9:
180+
ax.get_xaxis().set_visible(False)
181+
ax.spines['bottom'].set_visible(False)
182+
else:
183+
ax.set_xlabel('Depth ($mm$)')
184+
if i % 3 == 0:
185+
ax.set_ylabel('CSD ($mA/mm$)')
186+
ax.spines['right'].set_visible(False)
187+
ax.spines['top'].set_visible(False)
188+
# ht, lh = ax.get_legend_handles_labels()
189+
190+
# ax = fig.add_subplot(gs[3, :])
191+
# ax.legend(ht, lh, fancybox=False, shadow=False, ncol=len(src_idx),
192+
# loc='upper center', frameon=False, bbox_to_anchor=(0.5, 0.0))
193+
# ax.axis('off')
194+
195+
# plt.tight_layout()
196+
fig.legend(ht, lh, loc='lower center', ncol=5, frameon=False)
163197
fig.savefig(os.path.join(save_path, 'vectors_' + method +
164198
'_noise_' + str(noise) + '.png'), dpi=300)
165199

200+
#plt.show()
201+
166202

167203
if __name__ == '__main__':
168204
home = expanduser('~')

0 commit comments

Comments
 (0)