pyecharts之二

import pyecharts.charts as pyec
import pyecharts.options as opts

x=['甲','乙','丙']
y=[300,800,600]
bar=pyec.Bar()
bar.add_xaxis(x)
bar.add_yaxis(series_name='公司A',yaxis_data=y)
bar.render_notebook()
    

bar.set_global_opts(title_opts=opts.TitleOpts(title = '比较图'))
bar.render_notebook()
    
import pyecharts
pyecharts.__version__
'1.5.1'
#增加一个数据系列
y1 = [1200,500,200]
bar.add_yaxis(series_name = '公司B',yaxis_data=y1)
bar.render_notebook()

    
#条形图
bar.reversal_axis()
bar.render_notebook()
    
x1 = ['2017','2018','2019']
y1 = [300,900,600]
line = pyec.Line()
line.add_xaxis(x1)
line.add_yaxis(series_name = 'A',y_axis = y1)
#bar.set_global_opts(title_opts=opts.TitleOpts(title = '比较图'))
line.render_notebook()
    
y2 = [1300,500,900]
line.add_yaxis(series_name='B',y_axis=y2)
line.set_global_opts(title_opts=opts.TitleOpts(title = '比较图'))
line.render_notebook()
    
line.set_global_opts(title_opts=opts.TitleOpts(title = 'First'),legend_opts=opts.LegendOpts(is_show = True),tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='cross'))

line.render_notebook()
    
line.set_global_opts(title_opts=opts.TitleOpts(title = 'First'),legend_opts=opts.LegendOpts(is_show = True),tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='cross'),toolbox_opts=opts.ToolboxOpts(is_show = True,orient='horizontal'),datazoom_opts=opts.DataZoomOpts(type_ = 'slider',range_start=(),range_end=2500))
#vertical,竖着放
line.render_notebook()
    
line1 = pyec.Line(init_opts=opts.InitOpts(width = '500px',height='300px'))
line1.add_xaxis(x1)
line1.add_yaxis(series_name = "A",y_axis = y1)

line1.render_notebook()
    
x_data = ['直接访问','营销推广','博客推广','搜索引擎']
y_data = [830,214,399,1199]

data_pair = list(zip(x_data,y_data))
print(data_pair)

[('直接访问', 830), ('营销推广', 214), ('博客推广', 399), ('搜索引擎', 1199)]
pie = pyec.Pie()
pie.add(series_name = '推广渠道',data_pair = data_pair)
pie.render_notebook()
    
pie1 = pyec.Pie()
pie1.add(series_name = '',data_pair = data_pair,radius = ['40%','75%'])
pie1.set_global_opts(title_opts=opts.TitleOpts(title =''))
pie1.render_notebook()
    
#散点图
import numpy as np

x = np.linspace(0,10,30)
y1= np.sin(x)
y2 = np.cos(x)

scatter = pyec.Scatter()
scatter.add_xaxis(xaxis_data = x)
scatter.add_yaxis(series_name = '',y_axis = y1,label_opts=opts.LabelOpts(is_show = False))
scatter.render_notebook()
    
#控制点的大小:symbol_size = number
#形状:例如 symbol = 'circle'
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
x = '''
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''

y = x.lower()
print(y)
the zen of python, by tim peters

beautiful is better than ugly.
explicit is better than implicit.
simple is better than complex.
complex is better than complicated.
flat is better than nested.
sparse is better than dense.
readability counts.
special cases aren't special enough to break the rules.
although practicality beats purity.
errors should never pass silently.
unless explicitly silenced.
in the face of ambiguity, refuse the temptation to guess.
there should be one-- and preferably only one --obvious way to do it.
although that way may not be obvious at first unless you're dutch.
now is better than never.
although never is often better than *right* now.
if the implementation is hard to explain, it's a bad idea.
if the implementation is easy to explain, it may be a good idea.
namespaces are one honking great idea -- let's do more of those!
y = y.split()
print(y)
['the', 'zen', 'of', 'python,', 'by', 'tim', 'peters', 'beautiful', 'is', 'better', 'than', 'ugly.', 'explicit', 'is', 'better', 'than', 'implicit.', 'simple', 'is', 'better', 'than', 'complex.', 'complex', 'is', 'better', 'than', 'complicated.', 'flat', 'is', 'better', 'than', 'nested.', 'sparse', 'is', 'better', 'than', 'dense.', 'readability', 'counts.', 'special', 'cases', "aren't", 'special', 'enough', 'to', 'break', 'the', 'rules.', 'although', 'practicality', 'beats', 'purity.', 'errors', 'should', 'never', 'pass', 'silently.', 'unless', 'explicitly', 'silenced.', 'in', 'the', 'face', 'of', 'ambiguity,', 'refuse', 'the', 'temptation', 'to', 'guess.', 'there', 'should', 'be', 'one--', 'and', 'preferably', 'only', 'one', '--obvious', 'way', 'to', 'do', 'it.', 'although', 'that', 'way', 'may', 'not', 'be', 'obvious', 'at', 'first', 'unless', "you're", 'dutch.', 'now', 'is', 'better', 'than', 'never.', 'although', 'never', 'is', 'often', 'better', 'than', '*right*', 'now.', 'if', 'the', 'implementation', 'is', 'hard', 'to', 'explain,', "it's", 'a', 'bad', 'idea.', 'if', 'the', 'implementation', 'is', 'easy', 'to', 'explain,', 'it', 'may', 'be', 'a', 'good', 'idea.', 'namespaces', 'are', 'one', 'honking', 'great', 'idea', '--', "let's", 'do', 'more', 'of', 'those!']
d = {}
for i in y:
    d[i] = d.get(i,0) + 1
print(d)
{'the': 6, 'zen': 1, 'of': 3, 'python,': 1, 'by': 1, 'tim': 1, 'peters': 1, 'beautiful': 1, 'is': 10, 'better': 8, 'than': 8, 'ugly.': 1, 'explicit': 1, 'implicit.': 1, 'simple': 1, 'complex.': 1, 'complex': 1, 'complicated.': 1, 'flat': 1, 'nested.': 1, 'sparse': 1, 'dense.': 1, 'readability': 1, 'counts.': 1, 'special': 2, 'cases': 1, "aren't": 1, 'enough': 1, 'to': 5, 'break': 1, 'rules.': 1, 'although': 3, 'practicality': 1, 'beats': 1, 'purity.': 1, 'errors': 1, 'should': 2, 'never': 2, 'pass': 1, 'silently.': 1, 'unless': 2, 'explicitly': 1, 'silenced.': 1, 'in': 1, 'face': 1, 'ambiguity,': 1, 'refuse': 1, 'temptation': 1, 'guess.': 1, 'there': 1, 'be': 3, 'one--': 1, 'and': 1, 'preferably': 1, 'only': 1, 'one': 2, '--obvious': 1, 'way': 2, 'do': 2, 'it.': 1, 'that': 1, 'may': 2, 'not': 1, 'obvious': 1, 'at': 1, 'first': 1, "you're": 1, 'dutch.': 1, 'now': 1, 'never.': 1, 'often': 1, '*right*': 1, 'now.': 1, 'if': 2, 'implementation': 2, 'hard': 1, 'explain,': 2, "it's": 1, 'a': 2, 'bad': 1, 'idea.': 2, 'easy': 1, 'it': 1, 'good': 1, 'namespaces': 1, 'are': 1, 'honking': 1, 'great': 1, 'idea': 1, '--': 1, "let's": 1, 'more': 1, 'those!': 1}
d = list(d.items())
print(d)
[('the', 6), ('zen', 1), ('of', 3), ('python,', 1), ('by', 1), ('tim', 1), ('peters', 1), ('beautiful', 1), ('is', 10), ('better', 8), ('than', 8), ('ugly.', 1), ('explicit', 1), ('implicit.', 1), ('simple', 1), ('complex.', 1), ('complex', 1), ('complicated.', 1), ('flat', 1), ('nested.', 1), ('sparse', 1), ('dense.', 1), ('readability', 1), ('counts.', 1), ('special', 2), ('cases', 1), ("aren't", 1), ('enough', 1), ('to', 5), ('break', 1), ('rules.', 1), ('although', 3), ('practicality', 1), ('beats', 1), ('purity.', 1), ('errors', 1), ('should', 2), ('never', 2), ('pass', 1), ('silently.', 1), ('unless', 2), ('explicitly', 1), ('silenced.', 1), ('in', 1), ('face', 1), ('ambiguity,', 1), ('refuse', 1), ('temptation', 1), ('guess.', 1), ('there', 1), ('be', 3), ('one--', 1), ('and', 1), ('preferably', 1), ('only', 1), ('one', 2), ('--obvious', 1), ('way', 2), ('do', 2), ('it.', 1), ('that', 1), ('may', 2), ('not', 1), ('obvious', 1), ('at', 1), ('first', 1), ("you're", 1), ('dutch.', 1), ('now', 1), ('never.', 1), ('often', 1), ('*right*', 1), ('now.', 1), ('if', 2), ('implementation', 2), ('hard', 1), ('explain,', 2), ("it's", 1), ('a', 2), ('bad', 1), ('idea.', 2), ('easy', 1), ('it', 1), ('good', 1), ('namespaces', 1), ('are', 1), ('honking', 1), ('great', 1), ('idea', 1), ('--', 1), ("let's", 1), ('more', 1), ('those!', 1)]

wordcloud = pyec.WordCloud()
wordcloud.add(series_name = '',data_pair = d)
wordcloud.render_notebook()
    
#2019/11/7
from pyecharts.globals import ThemeType

x=['衬衫','羊毛衫','雪纺衫','裤子','高跟鞋','袜子']
y1 = [5,20,36,10,75,90]
y2 = [1,32,21,5,55,41]
y3 = [8,53,36,12,54,31]
y4 = [14,45,36,21,42,53]
bar = pyec.Bar()
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = '默认',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.LIGHT))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'LIGHT',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.DARK))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'DARK',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.CHALK))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'CHALK',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.ESSOS))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'ESSOS',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.INFOGRAPHIC))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'INFOGRAPHIC',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.MACARONS))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'MACARONS',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.PURPLE_PASSION))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'PURPLE_PASSION',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.ROMA))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'ROMA',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.ROMANTIC))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'ROMANTIC',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.SHINE))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'SHINE',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.VINTAGE))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'VINTAGE',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.WALDEN))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'WALDEN',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.WESTEROS))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'WESTEROS',subtitle='副标题'))
bar.render_notebook()
    
bar = pyec.Bar(init_opts=opts.InitOpts(theme = ThemeType.WONDERLAND))
bar.add_xaxis(x)
bar.add_yaxis(series_name = '',yaxis_data = y1)
bar.add_yaxis(series_name = '',yaxis_data = y2)
bar.add_yaxis(series_name = '',yaxis_data = y3)
bar.add_yaxis(series_name = '',yaxis_data = y4)
bar.set_global_opts(title_opts = opts.TitleOpts(title = 'WONDERLAND',subtitle='副标题'))
bar.render_notebook()
    
import datetime
import random
from pyecharts.charts import Calendar
def calendar_base() -> Calendar:
    begin = datetime.date(2017, 1, 1)
    end = datetime.date(2017, 12, 31)
    data = [
        [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
        for i in range((end - begin).days + 1)
    ]

    c = (
        Calendar()
        .add("", data, calendar_opts=opts.CalendarOpts(range_="2017"))
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Calendar-2017年微信步数情况"),
            visualmap_opts=opts.VisualMapOpts(
                max_=20000,
                min_=500,
                orient="horizontal",
                is_piecewise=True,
                pos_top="230px",
                pos_left="100px",
            ),
        )
    )
    return c
calendar_base().render_notebook()
    
from pyecharts.faker import Faker
from pyecharts import options as opts
from pyecharts.charts import Funnel, Page
funnel = Funnel()
data = [('a',6),('b',12),('c',32),('d',21),('e',43)]

funnel.add('',data)
funnel.render_notebook()
    
from pyecharts.charts import Gauge, Page

   
c = Gauge()
c.add("业务指标",[("完成率", 60)],
            split_number=5,
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(
                    color=[(0.6, "blue"), (0.7, "#37a2da"), (1, "#fd666d")], width=30
                )
            ),
            label_opts=opts.LabelOpts(formatter="{value}"),
        )
c.set_global_opts(
            title_opts=opts.TitleOpts(title="Gauge-分割段数-Label"),
            legend_opts=opts.LegendOpts(is_show=False),
        )
c.render_notebook()
    
from pyecharts.charts import Liquid

你可能感兴趣的:(pyecharts之二)