0

I have two 2d arrays that store data and I want to make a subplot in matplotlib consisting of two boxplots, however, I am encountering the error above whenever I try to put the two boxplots into a subplot. Each 2d array is m rows x n columns in dimension and for each array I draw one boxplot so that each column gets its own box within their respective boxplot. Drawing the boxplot works fine, but when I try to make a subplot containing the two boxplots, I get IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed. From the way it's worded I think it may be because of me using 2d arrays but I'm not sure. Am I filling the data incorrectly or something?

code:

cols = [0, 1, 2, 3, 4]
repeats = np.linspace(0, 49, 50)

array1 = np.zeros((len(repeats), len(cols))) # stores a numerical data value in each space
array2 = np.zeros((len(repeats), len(correl)))

#for i in range(len(cols)):
    for j in range(len(repeats)):  #data for array1 and array2 generated here
        pass
    

fig3, axs = plt.subplots(1, 2)

axs[0, 0] = plt.boxplot(array1, labels = cols)
axs[0, 1] = plt.boxplot(array1, labels = cols)
soapeater
  • 7
  • 3
  • 1
    `axs[0, 0] = plt.boxplot(array1, labels = cols)` ---> `axs[0].boxplot(array1, labels = cols)`, and similarly for the second `Axes`. – BigBen Jul 10 '23 at 19:21
  • Does this answer your question? [understanding matplotlib.subplots python](https://stackoverflow.com/questions/44598708/understanding-matplotlib-subplots-python) – BigBen Jul 10 '23 at 19:23
  • 1
    To piggyback off of @BigBen's suggestion, when you are only making one row or column of subplots, the result is a 1D array of axes. You only get a 2D result when creating a 2D array of subplots. – jared Jul 10 '23 at 19:24
  • @BigBen yep, thanks! – soapeater Jul 10 '23 at 23:04

0 Answers0