0

I am trying to create a 4X4 matrix of gridspec by iteration and embedding new gridspec inside the previous ones. I am using GridSpecFromSubplot, but I got the error ''SubplotSpec' object is not subscriptable'. I am attaching the code

I am trying to get a matrix of graphics composed by gridspec and those gridspec have other inner gridspec

ps: I am attaching the code here

%matplotlib widget
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec

x =[]
x.append(np.random.normal(-2.5, 1, 10000))
x.append(np.random.gamma(2, 1.5, 10000))
x.append(np.random.exponential(2, 10000))
x.append(np.random.uniform(14,20, 10000))
fig=plt.figure(figsize =(20,20))
gspec = gridspec.GridSpec(4,4,figure = fig)

for i in range(4):
    for j in range(4):
        gso=gspec[i][j]
        gs = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gso)
        top_histogram = plt.subplot(gs[0,1:])
        side_histogram =plt.subplot(gs[1:,0])
        lower_right = plt.subplot(gs[1:,1:])
        lower_right.scatter(x[i],x[j])
        top_histogram.hist(x[i], bins = 100)
        side_histogram.hist(x[j], bins = 100, orientation = 'horizontal')
        lower_right.get_xaxis().set_visible(False)
        lower_right.get_yaxis().set_visible(False)
        top_histogram.get_xaxis().set_visible(False)
        top_histogram.get_yaxis().set_visible(False)
        side_histogram.get_xaxis().set_visible(False)
        side_histogram.get_yaxis().set_visible(False)
        if i == 3:
            lower_right.get_xaxis().set_visible(True)
            side_histogram.get_yaxis().set_visible(True)
        if j == 0:
            side_histogram.get_xaxis().set_visible(True)
            top_histogram.get_yaxis().set_visible(True)
D.L
  • 4,339
  • 5
  • 22
  • 45
Paul
  • 1

0 Answers0