0
$\begingroup$

This is my data which is recorded in a dictionary. A sample of my dictionary looks like this: (id-s:{id-des:value})

{'1': {'1': 2.5039}, '2': {'2': 8.993242, '1': 8.972473}, '7': {'5': 6.4600, '7': 9.16026}, '3': {'5': 6.46004, '3': 8.8472, '6': 8.8266, '1': 8.806035}, '5': {'5': 8.70111}, '6': {'6': 8.8889}, '4': {'4': 9.55662}}

Firstly,I want to plot them in histograms. Every figure presents values of an id-s. Every bar presents values (2.5039 is the value in the first example).

I have tried with this code.

plt.subplots(len(param_dict), 1, sharex=True)
    plt.subplots_adjust(hspace=0.8)
    for key, src in param_dict.items():
        plt.title('Source : {}'.format(key), fontsize=9)
        print(key)
        for attribute, value in src.items():
            print('{} : {}'.format(attribute, value))
            plt.hist(value, bins=20, alpha=0.5, label='my label')

But it takes only the last data.

Secondly, I want to plot all of them in one histogram, all values whatever their id-s.

$\endgroup$
  • $\begingroup$ What is plt? You haven't imported it? $\endgroup$ – FinancialRadDeveloper Dec 18 '19 at 23:50
1
$\begingroup$

you can try this way:

dictonary = {'1': {'1': 2.5039}, '2': {'2': 8.993242, '1': 8.972473}, '7': {'5': 6.4600, '7': 9.16026}, '3': {'5': 6.46004, '3': 8.8472, '6': 8.8266, '1': 8.806035}, '5': {'5': 8.70111}, '6': {'6': 8.8889}, '4': {'4': 9.55662}}
new_dictonary = {str((k,k1)):v1 for k, v in dictonary.items() for k1,v1 in v.items()}
plt.figure(figsize=(15,5))
plt.bar(new_dictonary.keys(), new_dictonary.values(), width=.5, color='g')

bar plot

| improve this answer | |
$\endgroup$
  • $\begingroup$ thank you very much for your help. But I need the supblot too including a figure for every ,node. Could you check the code that I put please (my updated question) $\endgroup$ – dina Jan 25 '19 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.