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()
#增加一个数据系列
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)
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()
import this
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()