Issue
I am trying to plot the below sensitivity matrix into a plot that consists of each list as sub-plot in it. Preferably as a function and look like this one in seaborn tutorial.
I tried a similar way to plot the list of list but it only give me a single plot without subplots:
def scatter_plot(sen1_obs):
x = []
y = []
for i in sen1_obs:
x.append(i[0])
y.append(i[1])
plt.scatter(x,y)
plt.show()
And execute:
scatter_plot(sen1_obs)
My list look like this :
sen1_obs
Out[2]:
[array([[ 0.00040725, 0.00011072],
[ 0.0008145 , 0.00022144],
[-0.00040725, -0.00011072]]),
array([[ 8.32091781e-04, -8.06469105e-05],
[ 1.66418356e-03, -1.61293821e-04],
[-8.32091781e-04, 8.06469105e-05]]),
array([[ 0.00121915, 0.00033146],
[ 0.00243829, 0.00066291],
[-0.00121915, -0.00033146]]),
array([[ 0.00252797, -0.00024503],
[ 0.00505593, -0.00049006],
[-0.00252797, 0.00024503]]),
array([[ 0.00202743, 0.00055121],
[ 0.00405486, 0.00110242],
[-0.00202743, -0.00055121]]),
array([[ 0.00430218, -0.00041706],
[ 0.00860436, -0.00083411],
[-0.00430218, 0.00041706]]),
array([[ 3.08460052e-04, 8.38668514e-05],
[ 6.16920103e-04, 1.67733703e-04],
[-3.08460052e-04, -8.38668514e-05]]),
array([[ 0.00132295, -0.00012862],
[ 0.0026459 , -0.00025724],
[-0.00132295, 0.00012862]]),
array([[ 0.00089098, 0.00024225],
[ 0.00178196, 0.0004845 ],
[-0.00089098, -0.00024225]]),
array([[ 0.00402754, -0.00039161],
[ 0.00805507, -0.00078323],
[-0.00402754, 0.00039161]]),
array([[ 0.00149702, 0.00040703],
[ 0.00299405, 0.00081405],
[-0.00149702, -0.00040703]]),
array([[ 0.00665672, -0.00064722],
[ 0.01331343, -0.00129443],
[-0.00665672, 0.00064722]]),
array([[ 0.00879632, 0.00016573],
[ 0.01759264, 0.00033147],
[-0.00879632, -0.00016573]]),
array([[ 0.00728856, -0.00055898],
[ 0.01457712, -0.00111797],
[-0.00728856, 0.00055898]]),
array([[ 0.00913137, -0.00029702],
[ 0.01826274, -0.00059403],
[-0.00913137, 0.00029702]]),
array([[ 0.00463152, 0.00026766],
[ 0.00926303, 0.00053532],
[-0.00463152, -0.00026766]]),
array([[ 0.00315 , 0.00014372],
[ 0.0063 , 0.00028743],
[-0.00315 , -0.00014372]]),
array([[ 0.00607034, 0.00023261],
[ 0.01214067,
Solution
You can try something like this. I don't have a great way to use your data so disregard my first few lines of code that are making the data I am working with. But, essentially what you are doing is making a 5x5 grid to house your 22 subplots. You then create a list of lists for their positions in the subplot (we'll call it pos
). You then iterate over all the arrays in your variable en1_obs
and all the lists within your arrays. Delete the left over subplots (25-22 so 3 unused subplots) and you have your figure:
######### This is just code to make a (22,3,2) matrix to work with #########
import random
en1_obs = []
for x in range(22):
longlists = []
for y in range(3):
lists = []
for z in range(2):
lists.append(random.randint(1, 60))
longlists.append(lists)
en1_obs.append(np.array(longlists))
############################################################################
### This is the important code
plt.rcParams["figure.figsize"] = (20,10)
width = 5
height = 5
fig, ax = plt.subplots(height,width)
pos = [[x,y] for x in range(height) for y in range(width)]
count = 0
for i in en1_obs:
ax[pos[count][0],pos[count][1]].scatter(i[:, 0], i[:, 1])
count +=1
fig.delaxes(ax[4,2])
fig.delaxes(ax[4,3])
fig.delaxes(ax[4,4])
plt.show()
Answered By - Michael S.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.