python+echarts可视化—pyecharts
2020-03-14 本文已影响0人
生信编程日常
pyecharts是一个用于生成Echarts 图表的python库。Echarts(https://echarts.apache.org/examples/zh/index.html
)是一个数据可视化JS库,做出来的图非常好看。pyecharts这个项目可以在python中也生成这种风格的图。具体效果图可以参见该网站https://pyecharts.herokuapp.com/。
下面试举几例:
- 条形图 barplot
(点上去是可以互动的)
import pandas as pd
import pyecharts
from sklearn.datasets import load_iris
bar = (
pyecharts.charts.Bar()
.add_xaxis(["Gene1", "Gene2", "Gene3", "Gene4", "Gene5", "Gene6", "Gene7"])
.add_yaxis("CTCF", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("RAD21", [57, 134, 137, 129, 145, 60, 49])
.set_colors(['#00A383', '#FF6400'])
.set_global_opts(title_opts=opts.TitleOpts(title="Correlation"))
)
bar.render_notebook() # 如果不是jupyter notebook的话 bar.render()即可
barplot
- heatmap 热力图
import random
from pyecharts import options as opts
from pyecharts.charts import HeatMap
from pyecharts.faker import Faker
value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]
c = (
HeatMap()
.add_xaxis(Faker.clock)
.add_yaxis(
"",
Faker.week,
value,
label_opts=opts.LabelOpts(is_show=True, position="inside"),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="HeatMap"),
visualmap_opts=opts.VisualMapOpts(),
)
)
c.render_notebook()
heatmap
- Pie Plot 饼图
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker
c = (
Pie()
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"])
.set_global_opts(title_opts=opts.TitleOpts(title="Pie"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
c.render_notebook()
pie plot
- 地图
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
c = (
Map()
.add("", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
.set_global_opts(title_opts=opts.TitleOpts(title="Map"))
)
c.render_notebook()
map
此外还有桑葚图、雷达图等图,code示例可以详见https://gallery.pyecharts.org/#/Sankey/sankey_base来学习。
欢迎关注公众号!