本文整理汇总了Python中pyecharts.Bar类的典型用法代码示例。如果您正苦于以下问题:Python Bar类的具体用法?Python Bar怎么用?Python Bar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_grid_four_direction
def test_grid_four_direction():
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%")
bar.add("商家A", CLOTHES, v1, is_stack=True)
bar.add("商家B", CLOTHES, v2, is_stack=True, legend_pos="80%")
line = Line("折线图示例")
line.add("最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10],
mark_point=["max", "min"], mark_line=["average"])
line.add("最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0],
mark_point=["max", "min"], mark_line=["average"],
legend_pos="20%")
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
es = EffectScatter("动态散点图示例", title_top="50%")
es.add("es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0],
effect_scale=6, legend_top="50%", legend_pos="20%")
grid = Grid()
grid.add(bar, grid_bottom="60%", grid_left="60%")
grid.add(line, grid_bottom="60%", grid_right="60%")
grid.add(scatter, grid_top="60%", grid_left="60%")
grid.add(es, grid_top="60%", grid_right="60%")
grid.render()
示例2: test_numpy_array
def test_numpy_array():
v1 = np.array([5, 20, 36, 10, 75, 90])
bar = Bar(TITLE)
bar.add("商家A", CLOTHES, v1, is_stack=True)
html = bar.render_embed()
json_encoded_title = json.dumps(TITLE)
assert json_encoded_title in html
示例3: ax_draw_macd
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
"""绘制MACD
:param axes: 指定的坐标轴
:param KData kdata: KData
:param int n1: 指标 MACD 的参数1
:param int n2: 指标 MACD 的参数2
:param int n3: 指标 MACD 的参数3
"""
macd = MACD(CLOSE(kdata), n1, n2, n3)
bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2)
text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f'%(n1,n2,n3,fmacd[-1],smacd[-1],bmacd[-1])
#axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes)
total = len(kdata)
x_list = [i for i in range(total)]
y1_list = [round(x) if x > 0 else '-' for x in bmacd]
y2_list = [round(x) if x <= 0 else '-' for x in bmacd]
style = gcf().get_style(axes)
bar = Bar(subtitle=text, title_pos='10%', title_top='8%')
bar.add('1', x_list, y1_list, is_stack=True, is_legend_show=False, **style)
bar.add('2', x_list, y2_list, is_stack=True, is_legend_show=False, **style)
axes.add(bar)
fmacd.plot(axes=axes, line_type='dotted')
smacd.plot(axes=axes)
gcf().add_axis(axes)
return gcf()
示例4: create_three
def create_three():
page = Page(page_title=TEST_PAGE_TITLE)
# bar
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", CLOTHES, v1, is_stack=True)
bar.add("商家B", CLOTHES, v2, is_stack=True)
page.add(bar)
# scatter3D
import random
data = [
[random.randint(0, 100),
random.randint(0, 100),
random.randint(0, 100)] for _ in range(80)
]
scatter3d = Scatter3D("3D 散点图示例", width=1200, height=600)
scatter3d.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR)
page.add(scatter3d)
# guangdong
value = [20, 190, 253, 77, 65]
attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
map = Map("广东地图示例", width=1200, height=600)
map.add("", attr, value, maptype='广东', is_visualmap=True,
visual_text_color='#000')
page.add(map)
return page
示例5: test_grid_top_bottom
def test_grid_top_bottom():
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图示例", height=720)
bar.add("商家A", CLOTHES, v1, is_stack=True)
bar.add("商家B", CLOTHES, v2, is_stack=True)
line = Line("折线图示例", title_top="50%")
line.add(
"最高气温",
WEEK,
[11, 11, 15, 13, 12, 13, 10],
mark_point=["max", "min"],
mark_line=["average"],
)
line.add(
"最低气温",
WEEK,
[1, -2, 2, 5, 3, 2, 0],
mark_point=["max", "min"],
mark_line=["average"],
legend_top="50%",
)
grid = Grid()
grid.add(bar, grid_bottom="60%")
grid.add(line, grid_top="60%")
grid.render()
示例6: create_a_bar
def create_a_bar(title):
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar(title)
bar.add("商家A", CLOTHES, v1, is_stack=True)
bar.add("商家B", CLOTHES, v2, is_stack=True)
return bar
示例7: test_grid_properties
def test_grid_properties():
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图示例", height=720)
bar.add("商家A", CLOTHES, v1, is_stack=True)
bar.add("商家B", CLOTHES, v2, is_stack=True)
line = Line("折线图示例", title_top="50%")
line.add(
"最高气温",
WEEK,
[11, 11, 15, 13, 12, 13, 10],
mark_point=["max", "min"],
mark_line=["average"],
)
line.add(
"最低气温",
WEEK,
[1, -2, 2, 5, 3, 2, 0],
mark_point=["max", "min"],
mark_line=["average"],
legend_top="50%",
)
grid = Grid(width=1024, height=768)
grid.add(bar, grid_bottom="60%")
grid.add(line, grid_top="60%")
eq_(grid.width, 1024)
eq_(grid.height, 768)
assert (
("echarts" in bar.js_dependencies)
or ("echarts.min" in bar.js_dependencies)
)
示例8: test_bar_stack
def test_bar_stack():
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", CLOTHES, clothes_v1, is_stack=True)
bar.add("商家B", CLOTHES, clothes_v2, is_stack=True)
html_content = bar._repr_html_()
assert "dataZoom" not in html_content
assert "stack_" in html_content
示例9: test_bar_rotate_label
def test_bar_rotate_label():
days = ["{}天".format(i) for i in range(20)]
days_v1 = [random.randint(1, 20) for _ in range(20)]
bar = Bar("坐标轴标签旋转示例")
bar.add("", days, days_v1, xaxis_interval=0, xaxis_rotate=30,
yaxis_rotate=30)
assert "stack_" not in bar._repr_html_()
示例10: test_grid_add_overlap
def test_grid_add_overlap():
from pyecharts import Overlap
grid = Grid()
attr = ["{}月".format(i) for i in range(1, 13)]
v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
bar = Bar("Overlap+Grid 示例", width=1200, height=600, title_pos="40%")
bar.add("蒸发量", attr, v1)
bar.add(
"降水量",
attr,
v2,
yaxis_formatter=" ml",
yaxis_max=250,
legend_pos="85%",
legend_orient="vertical",
legend_top="45%",
)
line = Line()
line.add("平均温度", attr, v3, yaxis_formatter=" °C")
overlap = Overlap()
overlap.add(bar)
overlap.add(line, is_add_yaxis=True, yaxis_index=1)
grid.add(overlap, grid_right="20%")
grid.render()
示例11: test_bar_datazoom_undefined
def test_bar_datazoom_undefined():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom 默认 示例")
bar.add("", days, days_v1, is_label_show=True, is_datazoom_show=True)
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "slider"' in html_content
assert ': "inside"' not in html_content
示例12: create_demo_bar
def create_demo_bar(chart_id_demo=None):
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", attr, v1, is_stack=True)
bar.add("商家B", attr, v2, is_stack=True)
if chart_id_demo:
bar._chart_id = chart_id_demo
return bar
示例13: test_bar_datazoom_inside
def test_bar_datazoom_inside():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom - inside 示例")
bar.add("", days, days_v1, is_datazoom_show=True,
datazoom_type='inside', datazoom_range=[10, 25])
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "inside"' in html_content
assert ': "slider"' not in html_content
示例14: test_custom_template_for_chart
def test_custom_template_for_chart():
data = [{
'name': '衬衫',
'value': 5
}, {
'name': '羊毛衫',
'value': 20
}, {
'name': '雪纺衫',
'value': 36
}]
configure(echarts_template_dir='.')
online()
data1 = {'衬衫': '34', '羊毛衫': 45, '雪纺衫': 40}
names, values = Bar.cast(data)
names1, values1 = Bar.cast(data1)
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", names, values, is_stack=True)
bar.add("商家B", names1, values1, is_stack=True)
bar.render(path='new_version_bar.html')
with codecs.open('new_version_bar.html', 'r', 'utf-8') as f:
actual_content = f.read()
assert "</html>" in actual_content
示例15: test_numpy_array
def test_numpy_array():
import numpy as np
title = "柱状图数据堆叠示例"
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = np.array([5, 20, 36, 10, 75, 90])
bar = Bar(title)
bar.add("商家A", attr, v1, is_stack=True)
html = bar.render_embed()
json_encoded_title = json.dumps(title)
assert json_encoded_title in html