I have MultiIndexed pandas Series and am trying to plot each index in its own subplot, but it is running very slowly.
To accomplish the subplotting I am using a for loop over the outer level of MultiIndex, and plotting the Series using the inner index level as the x coordinate.
def plot_series( data ):
# create 16 subplots, corresponding to the 16 outer index levels
fig, axs = plt.subplots( 4, 4 )
for oi in data.index.get_level_values( 'outer_index' ):
# calculate subplot to use
row = int( oi/ 4 )
col = int( oi - row* 4 )
ax = axs[ row, col ]
data.xs( oi ).plot( use_index = True, ax = ax )
plt.show()
Each outer index level has 1000 data points, but the plotting takes several minutes to complete.
Is there a way to speed up the plotting?
Data
num_out = 16
num_in = 1000
data = pd.Series(
data = np.random.rand( num_out* num_in ),
index = pd.MultiIndex.from_product( [ np.arange( num_out ), np.arange( num_in ) ], names = [ 'outer_index', 'inner_index' ] )
)
index =channelcome from?