Plotting a bar chart from data in a python dictionary
Question: I have a dictionary in my python script that contains data I want to create a
bar chart with.

I used matplotlib and was able to generate the bar chart image and save it.
However that was not good enough because I want to send that bar chart out as
an email and I cannot embed the bar chart image in my email's html body. I
know I can use the `<img>` tag but the issue is that the email body is
populated in Jenkins as part of a pre-send script and externally generated
images cannot be sent out that way.

I am thinking of using D3.js to generate visualizations with the dictionary
data. I need help with where and how to start and glue python and js together.

FYI, currently I am using HTML package in python to generate html using python
code. This allows me to generate html tables very easily but html has not tags
for bar chart etc hence the issue.


Answer: As a minimal example for an html format bar chart generated from a python
`matplotlib` and `mpld3`, you have,

    
    
    import matplotlib.pyplot as plt
    import numpy as np
    import mpld3
    
    fig, ax = plt.subplots(1,1)
    N = 10
    bar = ax.bar(range(N),np.random.normal(size=N))
    mpld3.save_html(fig,'./out.html')
    

and then use `out.html` or call `mpld3.fig_to_html(fig)` to generate the code
or `mpld3.fig_to_dict` to output a json-serializable dictionary representation
of the figure.

