Generate multiple plots with for loop; display output in matplotlib subplots

Viewed 8556

Objective: To generate 100 barplots using a for loop, and display the output as a subplot image

Data format: Datafile with 101 columns. The last column is the X variable; the remaining 100 columns are the Y variables, against which x is plotted.

Desired output: Barplots in 5 x 20 subplot array, as in this example image: Subplot - 3 x 2 array example

Current approach: I've been using PairGrid in seaborn, which generates an n x 1 array: example output.

where input == dataframe; input3 == list from which column headers are called:

for i in input3:
    plt.figure(i)
    g = sns.PairGrid(input,
             x_vars=["key_variable"],
             y_vars=i,
             aspect=.75, size=3.5)
    g.map(sns.barplot, palette="pastel")

Does anyone have any ideas how to solve this?

2 Answers
Related