@@ -1147,7 +1147,7 @@ def index_to_time(self, index):
1147
1147
"""
1148
1148
return super (Visualize , self ).index_to_time (index )
1149
1149
1150
- def ionicfrac_evol_plot (self ,time_sequence , ion = 'all' ):
1150
+ def ionicfrac_evol_plot (self ,x_axis , ion = 'all' ):
1151
1151
"""
1152
1152
Creates a plot of the ionic fraction time evolution of element inputs
1153
1153
@@ -1158,8 +1158,9 @@ def ionicfrac_evol_plot(self,time_sequence, ion='all'):
1158
1158
ion: array-like, dtype=int
1159
1159
The repective integer charge of the atomic particle (i.e. 0 or [0,1])
1160
1160
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.
1163
1164
1164
1165
"""
1165
1166
#Check if element input is a string
@@ -1168,9 +1169,15 @@ def ionicfrac_evol_plot(self,time_sequence, ion='all'):
1168
1169
1169
1170
#Check if time input is in units of time
1170
1171
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
+
1174
1181
1175
1182
if ion == 'all' :
1176
1183
charge_states = pl .atomic .atomic_number (self .element ) + 1
@@ -1183,25 +1190,25 @@ def ionicfrac_evol_plot(self,time_sequence, ion='all'):
1183
1190
if ion == 'all' :
1184
1191
for nstate in range (charge_states ):
1185
1192
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 } )' )
1188
1195
plt .ylabel ('Ionic Fraction' )
1189
1196
plt .title ('Ionic Fraction Evolution of {}' .format (self .element ))
1190
- plt .legend ()
1197
+ plt .legend (loc = 'center left' )
1191
1198
else :
1192
1199
if charge_states .size > 1 :
1193
1200
for nstate in charge_states :
1194
1201
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 } )' )
1197
1204
plt .ylabel ('Ionic Fraction' )
1198
1205
plt .title ('Ionic Fraction Evolution of {}' .format (self .element ))
1199
1206
plt .legend ()
1200
1207
#plt.show()
1201
1208
else :
1202
1209
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 } )' )
1205
1212
plt .ylabel ('Ionic Fraction' )
1206
1213
plt .title ('Ionic Fraction Evolution of $%s^{%i+}$' % (self .element ,ion ))
1207
1214
#plt.show()
@@ -1242,7 +1249,8 @@ def ionicfrac_bar_plot(self, time_index):
1242
1249
color_idx ^= 1
1243
1250
1244
1251
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 ))
1246
1254
alpha -= 0.2
1247
1255
ax .set_xticks (charge_states - width / 2.0 )
1248
1256
ax .set_xticklabels (charge_states )
0 commit comments