本文整理汇总了Python中pygal.Line.x_labels方法的典型用法代码示例。如果您正苦于以下问题:Python Line.x_labels方法的具体用法?Python Line.x_labels怎么用?Python Line.x_labels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygal.Line
的用法示例。
在下文中一共展示了Line.x_labels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: graph
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def graph(graph, type, year, month):
"""Create graphs with the parameters passed."""
db = get_db()
now = datetime.now()
timestamp = now.timestamp()
time_first_day = datetime(year, month, 1).timestamp()
first_day = datetime(year, month, 1)
cal = calendar.monthrange(year, month)
time_last_day = datetime(year, month, cal[1], 23, 59, 59).timestamp()
last_day = datetime(year, month, cal[1])
if graph in ['ligne', 'histogramme']:
line_chart = Line(interpolate='cubic') if graph == 'ligne' else Bar()
if type == 'hour':
line_chart.title = (
'Somme des hoquets par heure en %s' %
calendar.month_name[month])
requete = db.execute(
'select CAST(strftime(\'%H\', datetime(moment, \'unixepoch\','
' \'localtime\')) as integer) as hour, count(*) from ok '
'where moment between (?) and (?) group by hour',
[time_first_day, time_last_day])
hoquet = dict(requete)
line_chart.x_labels = [
str(hour) for hour, val in sorted(hoquet.items())]
line_chart.add('Annabelle', [
val for hour, val in sorted(hoquet.items())])
else:
hoquet = []
x_labels = []
x_labels_major = []
line_chart.title = (
'Nombre de hoquets par jour en %s' %
calendar.month_name[month])
for i,day in enumerate(range (int(time_first_day),
int(time_last_day), 86400)):
if is_in_weekend(day):
requete = None
else:
requete = db.execute(
'select count(*) from ok where moment >= (?) '
'and moment <= (?)', [day, day+86400]).fetchone()[0]
x_labels_major.append(i+1)
x_labels.append(i+1)
hoquet.append(requete)
line_chart.x_labels = map(str, x_labels)
line_chart.x_labels_major = list(map(str, x_labels_major))
line_chart.add('Annabelle', hoquet)
return line_chart.render_response()
return gauge_chart.render_response()
示例2: test_only_major_dots
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_only_major_dots():
line = Line(show_only_major_dots=True,)
line.add('test', range(12))
line.x_labels = map(str, range(12))
line.x_labels_major = ['1', '5', '11']
q = line.render_pyquery()
assert len(q(".dots")) == 3
示例3: test_only_major_dots_count
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_only_major_dots_count():
line = Line(show_only_major_dots=True)
line.add('test', range(12))
line.x_labels = map(str, range(12))
line.x_labels_major_count = 2
q = line.render_pyquery()
assert len(q(".dots")) == 2
示例4: test_config_behaviours
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_config_behaviours():
line1 = Line()
line1.show_legend = False
line1.fill = True
line1.pretty_print = True
line1.x_labels = ['a', 'b', 'c']
line1.add('_', [1, 2, 3])
l1 = line1.render()
line2 = Line(
show_legend=False,
fill=True,
pretty_print=True,
x_labels=['a', 'b', 'c'])
line2.add('_', [1, 2, 3])
l2 = line2.render()
assert l1 == l2
class LineConfig(Config):
show_legend = False
fill = True
pretty_print = True
x_labels = ['a', 'b', 'c']
line3 = Line(LineConfig)
line3.add('_', [1, 2, 3])
l3 = line3.render()
assert l1 == l3
line4 = Line(LineConfig())
line4.add('_', [1, 2, 3])
l4 = line4.render()
assert l1 == l4
示例5: test_stroke_config
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_stroke_config():
line = Line(stroke_style={'width': .5})
line.add('test_no_line', range(12), stroke=False)
line.add('test', reversed(range(12)), stroke_style={'width': 3})
line.add(
'test_no_dots', [5] * 12,
show_dots=False,
stroke_style={
'width': 2,
'dasharray': '12, 31'
}
)
line.add(
'test_big_dots', [randint(1, 12) for _ in range(12)], dots_size=5
)
line.add(
'test_fill', [randint(1, 3) for _ in range(12)],
fill=True,
stroke_style={
'width': 5,
'dasharray': '4, 12, 7, 20'
}
)
line.x_labels = [
'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5', 'lol6', 'lol7',
'lol8', 'lol9', 'lol10', 'lol11'
]
return line.render_response()
示例6: _generate_time_chart
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def _generate_time_chart(self, datas):
"""
After generate a time chart,save to file and return the chart path
Keyword arguments:
datas -- Dict object of parsed information for a time chart
"""
if not datas:
return ""
line_chart = Line(x_label_rotation=30, sstyle=LightStyle, human_readable=True)
indices = sorted(datas.keys())
time_format = self.options["time_format"]
line_chart.x_labels = map(lambda x: dateutil.parser.parse(x).strftime(time_format), indices)
chart_data = {}
for index in indices:
for data in datas[index]:
if chart_data.get(data[0]):
chart_data.get(data[0]).append(data[1])
else:
chart_data[data[0]] = [data[1]]
for key in chart_data:
line_chart.add(key, chart_data[key])
path = os.path.join(tempfile.gettempdir(), "time{}.svg".format(str(int(time.time()))))
line_chart.render_to_file(path)
logging.info("Time chart was created successfully.")
return path
示例7: test_only_major_dots_every
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_only_major_dots_every():
"""Test major dots"""
line = Line(show_only_major_dots=True, x_labels_major_every=3)
line.add('test', range(12))
line.x_labels = map(str, range(12))
q = line.render_pyquery()
assert len(q(".dots")) == 4
示例8: test_parametric_styles_with_parameters
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_parametric_styles_with_parameters():
"""Test a parametric style with parameters"""
line = Line(style=RotateStyle(
'#de3804', step=12, max_=180, base_style=LightStyle))
line.add('_', [1, 2, 3])
line.x_labels = 'abc'
assert line.render()
示例9: test_simple_line
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_simple_line():
"""Simple line test"""
line = Line()
rng = range(-30, 31, 5)
line.add('test1', [cos(x / 10) for x in rng])
line.add('test2', [sin(x / 10) for x in rng])
line.add('test3', [cos(x / 10) - sin(x / 10) for x in rng])
line.x_labels = map(str, rng)
line.title = "cos sin and cos - sin"
q = line.render_pyquery()
assert len(q(".axis.x")) == 1
assert len(q(".axis.y")) == 1
assert len(q(".plot .series path")) == 3
assert len(q(".legend")) == 3
assert len(q(".x.axis .guides")) == 13
assert len(q(".y.axis .guides")) == 13
assert len(q(".dots")) == 3 * 13
assert q(".axis.x text").map(texts) == [
'-30', '-25', '-20', '-15', '-10', '-5',
'0', '5', '10', '15', '20', '25', '30']
assert q(".axis.y text").map(texts) == [
'-1.2', '-1', '-0.8', '-0.6', '-0.4', '-0.2',
'0', '0.2', '0.4', '0.6', '0.8', '1', '1.2']
assert q(".title").text() == 'cos sin and cos - sin'
assert q(".legend text").map(texts) == ['test1', 'test2', 'test3']
示例10: test_stroke_config
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_stroke_config():
line = Line(stroke_style={"width": 0.5})
line.add("test_no_line", range(12), stroke=False)
line.add("test", reversed(range(12)), stroke_style={"width": 3})
line.add("test_no_dots", [5] * 12, show_dots=False, stroke_style={"width": 2, "dasharray": "12, 31"})
line.add("test_big_dots", [randint(1, 12) for _ in range(12)], dots_size=5)
line.add(
"test_fill",
[randint(1, 3) for _ in range(12)],
fill=True,
stroke_style={"width": 5, "dasharray": "4, 12, 7, 20"},
)
line.x_labels = [
"lol",
"lol1",
"lol2",
"lol3",
"lol4",
"lol5",
"lol6",
"lol7",
"lol8",
"lol9",
"lol10",
"lol11",
]
return line.render_response()
示例11: test_config_behaviours
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_config_behaviours():
"""Test that all different way to set config produce same results"""
line1 = Line()
line1.show_legend = False
line1.fill = True
line1.pretty_print = True
line1.no_prefix = True
line1.x_labels = ['a', 'b', 'c']
line1.add('_', [1, 2, 3])
l1 = line1.render()
q = line1.render_pyquery()
assert len(q(".axis.x")) == 1
assert len(q(".axis.y")) == 1
assert len(q(".plot .series path")) == 1
assert len(q(".legend")) == 0
assert len(q(".x.axis .guides")) == 3
assert len(q(".y.axis .guides")) == 11
assert len(q(".dots")) == 3
assert q(".axis.x text").map(texts) == ['a', 'b', 'c']
line2 = Line(
show_legend=False,
fill=True,
pretty_print=True,
no_prefix=True,
x_labels=['a', 'b', 'c'])
line2.add('_', [1, 2, 3])
l2 = line2.render()
assert l1 == l2
class LineConfig(Config):
show_legend = False
fill = True
pretty_print = True
no_prefix = True
x_labels = ['a', 'b', 'c']
line3 = Line(LineConfig)
line3.add('_', [1, 2, 3])
l3 = line3.render()
assert l1 == l3
line4 = Line(LineConfig())
line4.add('_', [1, 2, 3])
l4 = line4.render()
assert l1 == l4
line_config = Config()
line_config.show_legend = False
line_config.fill = True
line_config.pretty_print = True
line_config.no_prefix = True
line_config.x_labels = ['a', 'b', 'c']
line5 = Line(line_config)
line5.add('_', [1, 2, 3])
l5 = line5.render()
assert l1 == l5
示例12: test_major_dots
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_major_dots():
line = Line(x_labels_major_count=2, show_only_major_dots=True)
line.add('test', range(12))
line.x_labels = [
'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5',
'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11']
# line.x_labels_major = ['lol3']
return line.render_response()
示例13: simulation
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def simulation():
x = w.x_odeint(w.initial)
line = Line(show_dots=False,show_minor_x_labels=False)
for c in x:
line.add(c,x[c])
line.x_labels = map(str,x.index.values)
line.x_labels_major = map(str,range(x.index[0],x.index[-1]+50,50))
return line.render_response()
示例14: test_one_dot
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_one_dot():
line = Line()
line.add('one dot', [12])
line.x_labels = ['one']
q = line.render_pyquery()
assert len(q(".axis.x")) == 1
assert len(q(".axis.y")) == 1
assert len(q(".y.axis .guides")) == 1
示例15: test_not_equal_x_labels
# 需要导入模块: from pygal import Line [as 别名]
# 或者: from pygal.Line import x_labels [as 别名]
def test_not_equal_x_labels():
line = Line()
line.add('test1', range(100))
line.x_labels = map(str, range(11))
q = line.render_pyquery()
assert len(q(".dots")) == 100
assert len(q(".axis.x")) == 1
assert q(".axis.x text").map(texts) == ['0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '10']