-1

I have a dictionary of dictionaries with the following structure:

{'ytrain_0': {'Neut': 0,'hard': 143,'hard linked': 1507,'soft': 112,'soft linked': 1238}, 
'ytrain_102000': {'Neut': 426,'hard': 519,'hard linked': 829,'soft': 467,'soft linked': 759}, 
'ytrain_105000': {'Neut': 406,'hard': 489,'hard linked': 826,'soft': 499,'soft linked': 780}}

This is just an example. My real dictionary has 78 dictionaries. Now what I want to do is that I want to make a histogram for each example (train_0,ytrain_102000,ytrain_105000). How can I do that in python? I haven't been able to figure that out.

Instead of creating 78 different graphs and adjusting it one image myself. I want to make 78 graphs in one image using python. I know we can do that in R using mfrow(). But I don't know how to do that in python? Can someone help me out with it?

I am using the following code to plot:

output = []

for a in dictionary_test.keys():
    output.append(dictionary_test[a])

import pandas as pd
pd.DataFrame(output).hist()

ax = pd.DataFrame(output).plot.bar(rot=0)

axes = pd.DataFrame(output).plot.bar(rot=0, subplots=True)
axes[1].legend(loc=2)

I get the following graph:

enter image description here

How to make sure that heading of each subplot does not appear on the other graph?

Peter
  • 97
  • 1
  • 9
  • Possible duplicate of [Plot a histogram from a Dictionary](https://stackoverflow.com/questions/21195179/plot-a-histogram-from-a-dictionary) – Devesh Kumar Singh May 31 '19 at 12:46
  • Maybe I should make it more clear. Instead of creating 78 different graphs and adjusting it one image myself. I want to make 78 graphs in one image using python. Does that make sense. I know we can do that in R using mfrow(). – Peter May 31 '19 at 12:52
  • then use subplot function of matplotlib library – Manuel May 31 '19 at 12:53

1 Answers1

0

try this:

dict = {'ytrain_0': {'Neut': 0,'hard': 143,'hard linked': 1507,'soft': 112,'soft linked': 1238},
'ytrain_102000': {'Neut': 426,'hard': 519,'hard linked': 829,'soft': 467,'soft linked': 759},
'ytrain_105000': {'Neut': 406,'hard': 489,'hard linked': 826,'soft': 499,'soft linked': 780}}

output = []

for a in dict.keys():
    output.append(dict[a]['Neut'])

import pandas as pd
pd.DataFrame(output).hist()

and the plot it with matplotlib library

Manuel
  • 117
  • 2
  • 9
  • Thank you for your answer. It helped me figure out. I've made a barplot. My question is why are some bars thick than others? And also, how can I make sure that the name of each graph doesn't appear on another graph like it does right now. I've attached the image and code I am using to produce it. – Peter May 31 '19 at 13:13