Skip to content

Commit f41c4ed

Browse files
committed
implemented more user-friendly ionic fraction plot paramters.
1 parent 4ae138c commit f41c4ed

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

nei/classes/nei.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def index_to_time(self, index):
11471147
"""
11481148
return super(Visualize, self).index_to_time(index)
11491149

1150-
def ionicfrac_evol_plot(self,time_sequence, ion='all'):
1150+
def ionicfrac_evol_plot(self,x_axis, ion='all'):
11511151
"""
11521152
Creates a plot of the ionic fraction time evolution of element inputs
11531153
@@ -1158,8 +1158,9 @@ def ionicfrac_evol_plot(self,time_sequence, ion='all'):
11581158
ion: array-like, dtype=int
11591159
The repective integer charge of the atomic particle (i.e. 0 or [0,1])
11601160
1161-
time_sequence: ~astropy.units.Quantity ,
1162-
The time array at which we will be plotting over
1161+
x_axis: ~astropy.units.Quantity: array-like ,
1162+
The xaxis to plot the ionic fraction evolution over.
1163+
Can only be distance or time.
11631164
11641165
"""
11651166
#Check if element input is a string
@@ -1168,9 +1169,15 @@ def ionicfrac_evol_plot(self,time_sequence, ion='all'):
11681169

11691170
#Check if time input is in units of time
11701171
try:
1171-
time = time_sequence.to(u.s)
1172-
except TypeError:
1173-
print("Invalid time units")
1172+
x = x_axis.to(u.s)
1173+
xlabel = 'Time'
1174+
except Exception:
1175+
x = x_axis.to(u.R_sun)
1176+
xlabel = 'Distance'
1177+
else:
1178+
raise TypeError('Invalid x-axis units. Can only be distance or time.')
1179+
1180+
11741181

11751182
if ion == 'all':
11761183
charge_states = pl.atomic.atomic_number(self.element) + 1
@@ -1183,25 +1190,25 @@ def ionicfrac_evol_plot(self,time_sequence, ion='all'):
11831190
if ion =='all':
11841191
for nstate in range(charge_states):
11851192
ionic_frac = self.results.ionic_fractions[self.element][:,nstate]
1186-
plt.plot(time.value,ionic_frac, linestyle= linsetyles[nstate % len(linsetyles)], label='%s+%i'%(self.element, nstate))
1187-
plt.xlabel('Time (s)')
1193+
plt.plot(x.value,ionic_frac, linestyle= linsetyles[nstate % len(linsetyles)], label='%s+%i'%(self.element, nstate))
1194+
plt.xlabel(f'{xlabel} ({x.unit})')
11881195
plt.ylabel('Ionic Fraction')
11891196
plt.title('Ionic Fraction Evolution of {}'.format(self.element))
1190-
plt.legend()
1197+
plt.legend(loc='center left')
11911198
else:
11921199
if charge_states.size > 1:
11931200
for nstate in charge_states:
11941201
ionic_frac = self.results.ionic_fractions[self.element][:,nstate]
1195-
plt.plot(time.value,ionic_frac, linestyle= linsetyles[nstate % len(linsetyles)], label='%s+%i'%(self.element, nstate))
1196-
plt.xlabel('Time (s)')
1202+
plt.plot(x.value,ionic_frac, linestyle= linsetyles[nstate % len(linsetyles)], label='%s+%i'%(self.element, nstate))
1203+
plt.xlabel(f'{xlabel} ({x.unit})')
11971204
plt.ylabel('Ionic Fraction')
11981205
plt.title('Ionic Fraction Evolution of {}'.format(self.element))
11991206
plt.legend()
12001207
#plt.show()
12011208
else:
12021209
ionic_frac = self.results.ionic_fractions[self.element][:,charge_states]
1203-
plt.plot(time.value,ionic_frac)
1204-
plt.xlabel('Time (s)')
1210+
plt.plot(x.value,ionic_frac)
1211+
plt.xlabel(f'{xlabel} ({x.unit})')
12051212
plt.ylabel('Ionic Fraction')
12061213
plt.title('Ionic Fraction Evolution of $%s^{%i+}$'%(self.element,ion))
12071214
#plt.show()
@@ -1242,7 +1249,8 @@ def ionicfrac_bar_plot(self, time_index):
12421249
color_idx ^= 1
12431250

12441251
ax.bar(charge_states, self.results.ionic_fractions[self.element][idx,:], alpha=alpha, \
1245-
width=width, color=colors[color_idx], label=f'Time:{self.index_to_time(idx)}')
1252+
width=width, color=colors[color_idx],
1253+
label='Time:{time:.{number}f}'.format(time=self.index_to_time(idx), number=1))
12461254
alpha -= 0.2
12471255
ax.set_xticks(charge_states-width/2.0)
12481256
ax.set_xticklabels(charge_states)

0 commit comments

Comments
 (0)