示例#1
0
文件: tests.py 项目: Kozea/pygal
 def test_bar():
     bar = Bar(dynamic_print_values=True, show_minor_x_labels=False)
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     bar.x_labels = [2, 4, 6]
     bar.x_labels_major = [4]
     return bar.render_response()
示例#2
0
文件: tests.py 项目: Bouska/pygal
    def test_bar_links():
        bar = Bar(style=styles['neon'])
        bar.js = ('http://l:2343/svg.jquery.js',
                  'http://l:2343/pygal-tooltips.js')
        bar.add('1234', [
            {'value': 10,
             'label': 'Ten',
             'xlink': 'http://google.com?q=10'},
            {'value': 20,
             'tooltip': 'Twenty',
             'xlink': 'http://google.com?q=20'},
            30,
            {'value': 40,
             'label': 'Forty',
             'xlink': 'http://google.com?q=40'}
        ])

        bar.add('4321', [40, {
            'value': 30,
            'label': 'Thirty',
            'xlink': 'http://google.com?q=30'
        }, 20, 10])
        bar.x_labels = map(str, range(1, 5))
        bar.logarithmic = True
        bar.zero = 1
        return bar.render_response()
示例#3
0
 def test_multiline_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = (
         'First line \n Second line \n Third line'
     )
     return bar.render_response()
示例#4
0
 def test_long_labels():
     bar = Bar()
     bar.add("Long", [2, None, 12])
     bar.title = "1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890"
     bar.x_labels = "a" * 100, "b " * 50, "cc ! " * 20
     bar.x_label_rotation = 45
     return bar.render_response()
示例#5
0
def test_another_sparktext():
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
示例#6
0
def test_xml_filters_round_trip():
    plot = Bar()
    plot.add("A", [60, 75, 80, 78, 83, 90])
    plot.add("B", [92, 87, 81, 73, 68, 55])
    before = plot.render()
    plot.add_xml_filter(lambda T: T)
    after = plot.render()
    assert before == after
示例#7
0
文件: graphs.py 项目: Qalthos/locutus
def graph_records(record_files):
    chart = Bar(BaseConfig)
    max_len = max(map(len, record_files.values()))
    for name, record_list in sort_domains(record_files.items()):
        chart.add(name, [x[0].total_seconds()/86400 for x in record_list] +
                        [None] * (max_len - len(record_list)))

    return chart.render()
示例#8
0
 def test_long_labels():
     bar = Bar()
     bar.add('Long', [2, None, 12])
     bar.title = (
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890')
     bar.x_labels = 'a' * 100, 'b ' * 50, 'cc ! ' * 20
     bar.x_label_rotation = 45
     return bar.render_response()
示例#9
0
 def __call__(self, T):
     subplot = Bar(legend_at_bottom=True, explicit_size=True, width=800, height=150)
     subplot.add("Difference", self.data)
     subplot = subplot.render_tree()
     subplot = subplot.xpath("g")[0]
     T.insert(2, subplot)
     T.xpath("g")[1].set('transform', 'translate(0,150), scale(1,0.75)')
     return T
示例#10
0
 def test_unsorted():
     bar = Bar(style=styles['neon'])
     bar.add('A', {'red': 10, 'green': 12, 'blue': 14})
     bar.add('B', {'green': 11, 'blue': 7})
     bar.add('C', {'blue': 7})
     bar.add('D', {})
     bar.add('E', {'blue': 2, 'red': 13})
     bar.x_labels = ('red', 'green', 'blue')
     return bar.render_response()
示例#11
0
def test_another_sparktext():
    """Test that same data produces same sparktext"""
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
示例#12
0
 def test_unsorted():
     bar = Bar(style=styles["neon"], human_readable=True)
     bar.add("A", {"red": 10, "green": 12, "blue": 14})
     bar.add("B", {"green": 11, "blue": 7})
     bar.add("C", {"blue": 7})
     bar.add("D", {})
     bar.add("E", {"blue": 2, "red": 13})
     bar.x_labels = ("red", "green", "blue")
     return bar.render_response()
示例#13
0
def test_xml_filters_change_bars():
    plot = Bar(legend_at_bottom=True, explicit_size=True, width=800, height=600)
    A = [60, 75, 80, 78, 83, 90]
    B = [92, 87, 81, 73, 68, 55]
    plot.add("A", A)
    plot.add("B", B)
    plot.add_xml_filter(ChangeBarsXMLFilter(A,B))
    q = plot.render_tree()
    assert len(q.xpath("g")) == 2
    assert q.xpath("g")[1].attrib["transform"] == "translate(0,150), scale(1,0.75)"
示例#14
0
 def test_bar_print_values():
     bar = Bar(print_values=True, js=[],
               style=styles['default'](
                   value_font_family='googlefont:Raleway',
                   value_font_size=30,
                   value_colors=(None, None, 'blue', 'red', 'green')
               ))
     for i in range(12):
         bar.add('', i)
     return bar.render_response()
示例#15
0
 def test_ylabels():
     chart = Bar()
     chart.x_labels = "Red", "Blue", "Green"
     chart.y_labels = [
         {"value": 0.0001, "label": "LOL"},
         {"value": 0.0003, "label": "ROFL"},
         {"value": 0.0004, "label": "MAO"},
         {"value": 0.00045, "label": "LMFAO"},
         {"value": 0.0005, "label": "GMCB"},
     ]
     chart.add("line", [0.0002, 0.0005, 0.00035])
     return chart.render_response()
示例#16
0
def test_simple_bar():
    bar = Bar()
    rng = [-3, -32, -39]
    bar.add("test1", rng)
    bar.add("test2", map(abs, rng))
    bar.x_labels = map(str, rng)
    bar.title = "Bar test"
    q = bar.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".legend")) == 2
    assert len(q(".plot .series rect")) == 2 * 3
示例#17
0
 def test_long_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = (
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 '
         '12345678901 123456789012 1234567890123 12345678901234 '
         '123456789012345 1234567890123456 12345678901234567 '
         '123456789012345678 1234567890123456789 12345678901234567890 '
         '123456789012345 1234567890123456 12345678901234567 '
         '12345678901 123456789012 1234567890123 12345678901234 '
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890')
     return bar.render_response()
示例#18
0
 def test_long_title():
     bar = Bar()
     bar.add("Looooooooooooooooooooooooooooooooooong", [2, None, 12])
     bar.title = (
         "1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 "
         "12345678901 123456789012 1234567890123 12345678901234 "
         "123456789012345 1234567890123456 12345678901234567 "
         "123456789012345678 1234567890123456789 12345678901234567890 "
         "123456789012345 1234567890123456 12345678901234567 "
         "12345678901 123456789012 1234567890123 12345678901234 "
         "1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890"
     )
     return bar.render_response()
示例#19
0
    def getBar(self):
        from pygal import Bar
        path = os.path.join(base_path, 'pygal_js', 'javascripts', 'bar', 'bar_chart.svg')
        config.width = 500
        config.height = 400
        bar_chart = Bar(config, width=400, height=300, legend_box_size=10)
        bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])  # Add some values
        bar_chart.render_to_file(path)
        #fileio = StringIO()
        #im.save(fileio, 'svg')
        ##im.save('img.gif', 'gif')
        #im.show()
        #return ''.join(char), fileio

        return os.path.join(SVG_PATH, 'bar', 'bar_chart.svg')
示例#20
0
 def test_ylabels():
     chart = Bar()
     chart.x_labels = 'Red', 'Blue', 'Green'
     chart.y_labels = [
         {'value': .0001,
          'label': 'LOL'},
         {'value': .0003,
          'label': 'ROFL'},
         {'value': .0004,
          'label': 'MAO'},
         {'value': .00045,
          'label': 'LMFAO'},
         {'value': .0005,
          'label': 'GMCB'}]
     chart.add('line', [.0002, .0005, .00035])
     return chart.render_response()
示例#21
0
def test_chart_renders():
    line_chart = Bar(print_values=True, percent_values=True, print_values_position='top')
    line_chart.title = 'Browser usage evolution (in %)'
    line_chart.x_labels = map(str, range(2002, 2013))
    line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
    line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
    line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
    line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
    assert line_chart.render()
示例#22
0
文件: tests.py 项目: Cortana-/pygal
    def test_bar_links():
        bar = Bar(style=styles["neon"])
        bar.js = ("http://l:2343/svg.jquery.js", "http://l:2343/pygal-tooltips.js")
        bar.add(
            "1234",
            [
                {"value": 10, "label": "Ten", "xlink": "http://google.com?q=10"},
                {"value": 20, "tooltip": "Twenty", "xlink": "http://google.com?q=20"},
                30,
                {"value": 40, "label": "Forty", "xlink": "http://google.com?q=40"},
            ],
        )

        bar.add("4321", [40, {"value": 30, "label": "Thirty", "xlink": "http://google.com?q=30"}, 20, 10])
        bar.x_labels = map(str, range(1, 5))
        bar.logarithmic = True
        bar.zero = 1
        return bar.render_response()
示例#23
0
def test_difference():
    bar = Bar(bar_values=False)
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)
    bar_labelled = Bar(bar_values=True)
    rng = [-3, -32, -39]
    bar_labelled.add('test1', rng)
    bar_labelled.add('test2', map(abs, rng))
    bar.labelled = map(str, rng)

    assert bar != bar_labelled
示例#24
0
def test_difference():
    """Tests the difference between labeled graphs and unlabeled graphs"""
    bar = Bar(bar_values=False)
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)
    bar_labelled = Bar(bar_values=True)
    rng = [-3, -32, -39]
    bar_labelled.add('test1', rng)
    bar_labelled.add('test2', map(abs, rng))
    bar.labelled = map(str, rng)

    assert bar != bar_labelled
示例#25
0
def test_bar_percent_difference():
    bar = Bar()
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)

    barpercent = Bar(percent_values=True)
    rng = [-3, -32, -39]
    barpercent.add('test1', rng)
    barpercent.add('test2', map(abs, rng))
    barpercent.x_labels = map(str, rng)

    assert (bar != barpercent)
示例#26
0
def test_bar_percent_difference():
    """Tests the difference between percent labeled graphs and unlabeled graphs"""
    bar = Bar()
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)

    barpercent = Bar(percent_values=True)
    rng = [-3, -32, -39]
    barpercent.add('test1', rng)
    barpercent.add('test2', map(abs, rng))
    barpercent.x_labels = map(str, rng)

    assert (bar != barpercent)
示例#27
0
    def get(self):
        from pygal import Bar
        path = os.path.join(base_path, 'pygal_js', 'javascripts', 'bar', 'bar_chart.svg')
        config.width = 500
        config.height = 400
        #bar_chart = Bar(config, width=400, height=300, legend_box_size=10)
        args = self.args
        for k, v in args.items():
            if v.isdigit():
                args[k] = int(v)
        bar_chart = Bar(config, **args)
        data = self.args.get("data", "")
        x_labels = self.args.get("x_labels", "")
        bar_chart.add('Fibonacci', [int(i) for i in data.split(",")])  # Add some values
        bar_chart.x_labels = x_labels.split(",")
        bar_chart.render_to_file(path)
        #fileio = StringIO()
        #im.save(fileio, 'svg')
        ##im.save('img.gif', 'gif')
        #im.show()
        #return ''.join(char), fileio

        return self.write(simplejson.dumps({"data":os.path.join(SVG_PATH, 'bar', 'bar_chart.svg')}))
示例#28
0
            'xlink': f"https://news.ycombinator.com/item?id={id_article}"
        }
        articles.append(about_article)

# сортируем список статей по кол-ву комментариев
articles = sorted(articles, key=itemgetter('value'), reverse=True)
print(articles)

# формируем список из названий статей
names = []
for article in articles:
    names.append(article['label'])

# задание стилей для диаграммы
my_config = Config()
my_config.x_label_rotation = 45
my_config.show_legend = False
my_config.truncate_label = 25  # сокращение длинных названий проектов
my_config.show_y_guides = False  # скроем горизонтальные линии
my_config.width = 1300
my_style = style.LightenStyle('#333366', base_style=style.LightColorizedStyle)
my_style.label_font_size = 16
my_style.major_label_font_size = 20

# построение визуализации
chart = Bar(my_config, style=my_style)
chart.title = "Активные обсуждения на Hack News"
chart.x_labels = names
chart.add('', articles)
chart.render_to_file("popular_articles_hack_news.svg")
示例#29
0
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     bar.x_labels = range(1, 4)
     return bar.render_response()
示例#30
0
 def test_bar():
     bar = Bar()
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     bar.x_labels = ['a']
     return bar.render_response()
示例#31
0
 def test_multiline_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = ('First line \n Second line \n Third line')
     return bar.render_response()
示例#32
0
 def test_bar():
     bar = Bar()
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     return bar.render_response()
示例#33
0
from die import Die
from pygal import Bar

#Creates two D6 dice (D6 == die of 6 sides)
die = Die()

times = 1000

#Roll the die and store the results in a list
results = [die.roll() for roll_num in range(times)]

#Analize the results
frequencies = [results.count(value) for value in range(1, die.sides + 1)]

#Visualizes the results
hist = Bar()

hist.title = 'Results of rolling one D6 die ' + str(times) + ' times'
hist.x_labels = [str(i) for i in range(1, 7)]
hist.x_title = 'Sides'
hist.y_title = 'Frequency of Side'

#add will add automatically the y_labels
hist.add('D6', frequencies)
hist.render_to_file('die_visual.svg')
示例#34
0
try:
    nb_of_rolls = int(input('Enter the desired number of rolls: '))
    if nb_of_rolls < 1:
        raise ValueError
except ValueError:
    print(
        'Input was not provided or invalid, so the default value of 1,000 will be used.'
    )
    nb_of_rolls = 1000

rolls = [
    sum(randint(1, nb_of_sides) for nb_of_sides in dice)
    for _ in range(nb_of_rolls)
]
range_of_sums = range(len(dice), sum(dice) + 1)
counts = [rolls.count(i) for i in range_of_sums]
counts = [{
    'value': count,
    'label': 'Frequency: {:.2f}'.format(count / nb_of_rolls)
} for count in counts]
histogram = Bar(style=Style(colors=('#228B22', ), major_label_font_size=12),
                show_legend=False)
histogram.title = 'Simulation for {} rolls of the dice: {}'.format(
    nb_of_rolls, sorted(dice))
histogram.x_labels = [str(i) for i in range_of_sums]
histogram.x_title = 'Possible sums'
histogram.y_title = 'Counts'
histogram.add('', counts)
histogram.render_to_file('dice_rolls.svg')
示例#35
0
from die import Die
from pygal import Bar

die_1 = Die()
# 十面骰子
die_2 = Die(10)
results = []
frequencies = []
for roll in range(10000):
    result = die_1.roll() + die_2.roll()
    results.append(result)
max_result = die_1.num_sides + die_2.num_sides
for value in range(2, max_result + 1):
    frequency = results.count(value)
    frequencies.append(frequency)

hist = Bar()
hist.title = "Results of rolling a D6 and a D10 10000 times."
# 随着数据的增大,最好利用循环生成x坐标列表
hist.x_labels = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
hist.x_title = "Result"
hist.y_title = "Frequency of Results"
hist.add("D6+D10", frequencies)
hist.render_to_file("die_simulation_pro.svg")
示例#36
0
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     return bar.render_response()
示例#37
0
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     return bar.render_response()
示例#38
0
from throw_dice.die import Die
from pygal import Bar

# создание кубиков
die_1 = Die(8)
die_2 = Die(8)

# моделирование серии бросков с сохранением данных
max_throws = 10000
results = [die_1.roll() + die_2.roll() for roll_num in range(max_throws)]
print(results)

# анализ результатов
max_result = die_1.num_sides + die_2.num_sides
frequencies = [results.count(value) for value in range(2, max_result + 1)]
print(frequencies)

# визуализация результатов
histogram = Bar()
histogram.title = f"Результаты брасания двух кубиков {max_throws} раз"
histogram.x_labels = [num for num in range(2, max_result + 1)]
histogram.x_title = "Сумма выпадений"
histogram.y_title = "Количество выпадений"
histogram.add("Сумма граней кубиков", frequencies)
histogram.render_to_file('dice_visual.svg')
示例#39
0
 def test_bar():
     bar = Bar()
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     bar.x_labels = ['a']
     return bar.render_response()
示例#40
0
 def show_walk(self):
     hist = Bar()
     hist.title = 'Random Walk'
     hist.add('X Values', self.x_values)
     hist.add('Y Values', self.y_values)
     hist.render_to_file('randomwalk.svg')
示例#41
0
文件: Task5.py 项目: YawenRiva/UNSW
xlab = []
items = []
begin = lb
end = ub
while count[begin] == 0:
    begin += 1
while count[end] == 0:
    end -= 1
for i in range(begin, end):
    xlab.append(i)
    dic = {"value": count[i],
           "label": f"Frequency: {count[i] / n:.2f}"}
    items.append(dic)
#
# Render
barch = Bar()
barch.title = f"Simulation for {n} rolls of the dice: {dice}"
barch.x_labels = xlab
barch.x_title = "Possible sums"
barch.y_title = "Counts"
barch.show_legend = False
barch.force_uri_protocol = "http"
barch.add('', items)
barch.style = Style(colors=("#228B22",),
                    label_font_size=12)
barch.render()
barch.render_to_file("dice_rolls.svg")
#
# Open browser window
open_new_tab("file://" + path.realpath("dice_rolls.svg"))
示例#42
0
 def test_long_title():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     bar.title = '123456789 ' * 30
     return bar.render_response()