from pyecharts import options as opts
from pyecharts.charts import Bar, Timeline
from pyecharts.commons.utils import JsCode
from pyecharts.faker import Faker
x = Faker.choose()
timeline = Timeline()
for i in range(2015, 2020):
bar = (
Bar()
.add_xaxis(x)
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts("某商店{}年营业额 - With Graphic 组件".format(i))
)
)
timeline.add(bar, "{}年".format(i))
timeline.render_notebook()
#示例展示前四个省近年gdp的变化
import pyecharts.options as opts
import pandas as pd
from pyecharts.charts import Line
df = pd.read_csv(r"gdp.csv")
year = list(df)[1::][::-1] #读取年份
pro = df['province'].tolist()[:4] #读取前四个省
# line+zoom
line_zoom = (
Line()
.add_xaxis(year)
.add_yaxis(pro[0],df.loc[0].tolist()[1:][::-1])
.add_yaxis(pro[1],df.loc[1].tolist()[1:][::-1])
.add_yaxis(pro[2],df.loc[2].tolist()[1:][::-1])
.add_yaxis(pro[3],df.loc[3].tolist()[1:][::-1])
.set_global_opts(
xaxis_opts=opts.AxisOpts(name="x"),
yaxis_opts=opts.AxisOpts(
type_="log",
name="y",
splitline_opts=opts.SplitLineOpts(is_show=True),
is_scale=True,
),
datazoom_opts=opts.DataZoomOpts(orient="vertical",range_start=0,range_end=60,pos_left='1%')
)
)
line_zoom.render_notebook()
import pandas as pd
import streamlit as st
from pyecharts import options as opts
from pyecharts.charts import Bar
df = pd.read_csv(r"gdp.csv")
df = df.iloc[:4,:].set_index('province') #选择所需要的数据,iloc[[行],[列]]
pro = list(df.index) #城市列表
years = list(df)[::-1] #年份列表
select_year = st.slider('Select the year you want to view',1997,2016) #选择查看的年份
real_year = years[select_year - 1997] #真正的年份
#柱状图
bar = (
Bar()
.add_xaxis(pro) #x的值
.add_yaxis(real_year, df[real_year].tolist()) #(标签,y的值)
.set_global_opts(title_opts=opts.TitleOpts("{} Gdp".format(real_year))) #标题
)
"""
从 Python 可视化库呈现图表
st.components.v1.html(html, width=None, height=None, scrolling=False)
"""
st.components.v1.html(bar.render_embed(),width=1000,height=1000)
1)先下载好metabase.jar文件和数据库sakila文件
2)将sakila中的文件放入MySQL中运行得到sakila数据库
3)打开Metabase:
[1]按shift + 鼠标右键出现【打开Powershell窗口】;
[2]在窗口中运行 java -jar metabase.jar
[3]在命令行中找到网址在浏览器打开,即可打开Metabase
4)导入数据库:
[1]找到左下角设置符号点击管理员设置
[2]点击 “添加一个数据库”
[3]如图配置(账号密码为MySQL中的),运行成功则数据库导入成功啦
再在右上角新建一个问题,选取想要分析的表和字段进行视觉化,并选取视觉化图表类型
然后把图加到仪表板中即可