1

I'm having two list which it self consist of lists. I want to plot a histogram using these lists.

following are the lists:

param_main_list

[['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2'], 
['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2', 
'Question3', 'Answer3', 'Question4', 'Answer4', 'Question5', 'Answer5'], 
['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2', 
'Question3', 'Answer3', 'Question4', 'Answer4', 'Question5', 'Answer5'], 
['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2', 
'Question3', 'Answer3', 'Question4', 'Answer4', 'Question5', 'Answer5']]

main_list:

[1107, 64, 129, 64, 67]
[1223, 34, 129, 62, 244, 56, 136, 48, 128, 43, 180]
[1345, 47, 96, 63, 241, 79, 97, 82, 108, 62, 134]
[648, 35, 111, 78, 131, 56, 86, 28, 47, 64, 151]
[[1107, 64, 129, 64, 67], [1223, 34, 129, 62, 244, 56, 136, 48, 128, 43, 
180], [1345, 47, 96, 63, 241, 79, 97, 82, 108, 62, 134], [648, 35, 111, 
78, 131, 56, 86, 28, 47, 64, 151]]

Consider these histogram take one to one correspondence from the list i.e 1st elem of param_main_list and 1st elem of main_list

I'm able to print a single histogram but I want multiple histogram for each cases separetly. The one I have generated is below

enter image description here

the code for above is:

for index in range(0,len(main_list)):     
    xpos = np.arange(len(main_list[index]))   
    plt.xticks(xpos,param_main_list[index])
    plt.bar(param_main_list[index],main_list[index])
    plt.hist() 

This ain't a duplicate I have checked all solutions , please help me with this.

andro
  • 37
  • 8
  • Checkout :https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib/31728991 – Born Tbe Wasted Apr 09 '19 at 10:55
  • Possible duplicate of [How do I get multiple subplots in matplotlib?](https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib) – Georgy Apr 09 '19 at 12:04

1 Answers1

0

iterate through the axs of the subplot

%matplotlib inline
import matplotlib.pyplot as plt
x=[['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2'], 
['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2','Question3', 'Answer3', 'Question4', 'Answer4', 'Question5', 'Answer5'], 
['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2','Question3', 'Answer3', 'Question4', 'Answer4', 'Question5', 'Answer5'], 
['Para_length', 'Question1', 'Answer1', 'Question2', 'Answer2','Question3', 'Answer3', 'Question4', 'Answer4', 'Question5', 'Answer5']]  

y=[[1107, 64, 129, 64, 67], 
[1223, 34, 129, 62, 244, 56, 136, 48, 128, 43, 180], 
[1345, 47, 96, 63, 241, 79, 97, 82, 108, 62, 134], 
[648, 35, 111, 78, 131, 56, 86, 28, 47, 64, 151]]


fig, axs = plt.subplots(1,4)

for i,ax in enumerate(axs):
    ax.bar(x[i],y[i])
    ax.set_xticklabels(x[i], rotation=90)


plt.show()
Shijith
  • 4,602
  • 2
  • 20
  • 34