私が使用しているソリューション
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)