0

Looking for system to create bar chart from dictionary have around 150 lines to put in charts.

{'test.com': Decimal('40'), 'cmi.com': Decimal('70'), 'dublin.ie': Decimal('5'), 'sfss.edu': Decimal('35'), 'computer.ie': Decimal('10')}

What have been doing is put for loop and making it image width but not working as dynamically as want it.

print "<img src='line.png' width='%d'>" % email[1]

Any help would be great.

namit
  • 113
  • 3
  • 8
  • What library are you using for this? – Makoto Jan 20 '13 at 16:55
  • in python: http://matplotlib.org/examples/api/barchart_demo.html or using javascript: http://stackoverflow.com/questions/119969/javascript-chart-library – namit Jan 20 '13 at 17:19
  • http://stackoverflow.com/questions/7871338/creating-bar-charts-in-python – Rachel Gallen Jan 20 '13 at 17:36
  • Am getting _tkinter.TclError: no display name and no $DISPLAY environment variable quite certain this is because X is not on my server and this is how it gets. – namit Jan 20 '13 at 21:30

2 Answers2

0

With combination of

Creating Bar Charts in Python and Generating a PNG with matplotlib when DISPLAY is undefined

Was able to solve this thanks for help.

#!/usr/bin/env python
print 'Content-type: text/html'
print.
import numpy as np
import matplotlib as mpl
mpl.use('Agg')

import matplotlib.pyplot as plt

Thank you

Community
  • 1
  • 1
namit
  • 113
  • 3
  • 8
0

Solution i am using

import matplotlib

matplotlib.use('Agg')
from pylab import *
from decimal import *

def main(my_dict):..
    bar_graph(my_dict, graph_title='Custoers')
    show_html()

def bar_graph(name_value_dict, graph_title='', output_name='bargraph.png'):
    figure(figsize=(15, 10)) # image dimensions..
    title(graph_title, size='x-small')

    # add bars
    for i, key in zip(range(len(name_value_dict)), name_value_dict.keys()):
        barh(i, name_value_dict[key], color='red')

    # axis setup
    yticks(arange(0, len(name_value_dict)),
        [('%s: %d \n' % (name)) for name in
        zip(name_value_dict.keys(), name_value_dict.values())],
        size='small')

# max_value = max(name_value_dict.values())
#tick_range = arange(0, max_value, (max_value / len(ame_val_dict)))
#formatter = FixedFormatter([str(x) for x in tick_range])
# gca().yaxis.set_major_formatter(formatter)

    # gca().yaxis.grid(which='major')
    grid(True).
    savefig(output_name)

def show_html():
    #print "<html><body>"
    print "<img src='bargraph.png'>"
    #print "</body></html>"

if __name__ == "__main__":
    my_dict = {'la' : Decimal('20'), 'cmi' : Decimal(100)}
    main(my_dict)
namit
  • 113
  • 3
  • 8