0

寻找从字典创建条形图的系统有大约 150 行可以放入图表。

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

一直在做的是 for 循环并使其成为图像宽度,但不能像想要的那样动态地工作。

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

任何帮助都会很棒。

4

2 回答 2

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)
于 2013-01-21T00:43:13.643 回答
0

结合

当 DISPLAY 未定义时,在 Python 中创建条形图使用 matplotlib 生成 PNG

能够解决这个感谢帮助。

#!/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

谢谢

于 2013-01-20T21:52:06.053 回答