PyEcharts 基本图表之日历图
程序员文章站
2022-05-26 22:01:51
...
第1关 Calendar:日历图(一)
from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
import random
import datetime
from pyecharts.charts import Calendar
begin = datetime.date(2020, 1, 1)
end = datetime.date(2020, 12, 31)
data = [
[str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
for i in range((end - begin).days + 1)
]
def calendar_chart() -> Calendar:
# ********* Begin *********#
calendar = (
Calendar()
.add("",data,calendar_opts=opts.CalendarOpts(range_="2020"))
.set_global_opts(
title_opts=opts.TitleOpts(title="Calendar-2020年微信步数情况"),
visualmap_opts=opts.VisualMapOpts(
max_=30000,
min_=500,
orient="horizontal",
is_piecewise=True,
pos_top="230px",
pos_left="100px",
),
)
)
# ********** End **********#
return calendar
make_snapshot(snapshot, calendar_chart().render("Result/render.html"), 'StudentAnswer/student_answer.png') # 输出图片
make_snapshot(snapshot, calendar_base(data).render(), "StandardAnswer/task1/standard_answer_1.png")
第2关 Calendar:日历图(二)
from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
import random
import datetime
from pyecharts.charts import Calendar
begin = datetime.date(2020, 1, 1)
end = datetime.date(2020, 12, 31)
data = [
[str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
for i in range((end - begin).days + 1)
]
def calendar_chart() -> Calendar:
# ********* Begin *********#
calendar = (
Calendar()
.add(
"",
data,
calendar_opts=opts.CalendarOpts(
range_="2020",
# 注意到这里name_map = "cn" ,name_map="cn" 使用的是中文标签。
daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="Calendar-2020年微信步数情况(中文 Label)"),
visualmap_opts=opts.VisualMapOpts(
max_=30000,
min_=500,
orient="horizontal",
is_piecewise=True, # 这里是True 表示可以选择是否出现。
pos_top="230px",
pos_left="100px",
),
)
)
# ********** End **********#
return calendar
make_snapshot(snapshot, calendar_chart().render("Result/render.html"), 'StudentAnswer/student_answer.png') # 输出图片
make_snapshot(snapshot, calendar_label_setting(data).render(), "StandardAnswer/task2/standard_answer_2.png")
第3关 Calendar:日历图(三)
from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
import random
import datetime
from pyecharts.charts import Calendar
begin = datetime.date(2020, 1, 1)
end = datetime.date(2020, 12, 31)
data = [
[str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
for i in range((end - begin).days + 1)
]
def calendar_chart() -> Calendar:
# ********* Begin *********#
calendar = (
Calendar(init_opts=opts.InitOpts(width="1600px", height="350px"))
.add(
series_name="", # 名字
yaxis_data=data, # 数据
calendar_opts=opts.CalendarOpts(
# 上左右边界
pos_top="120",
pos_left="30",
pos_right="30",
range_="2020",
yearlabel_opts=opts.CalendarYearLabelOpts(is_show=False),
),
)
.set_global_opts(
title_opts=opts.TitleOpts(pos_top="30", pos_left="center", title="2020年步数情况"),
visualmap_opts=opts.VisualMapOpts(
max_=30000, min_=500, orient="horizontal", is_piecewise=False
)
)
)
# ********** End **********#
return calendar
make_snapshot(snapshot, calendar_chart().render("Result/render.html"), 'StudentAnswer/student_answer.png') # 输出图片
make_snapshot(snapshot, calendar_heatmap(data).render(), "StandardAnswer/task3/standard_answer_3.png")
上一篇: Android随笔之简单仪表盘
下一篇: (日历)Calendar