图及可视化

各种线图:

import mpf as mpf
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
# import matplotlib.finance as mpf
from mpl_toolkits.mplot3d import Axes3D
'''
axex: 设置坐标轴边界和表面的颜色、坐标刻度值大小和网格的显示
backend: 设置目标暑促TkAgg和GTKAgg
figure: 控制dpi、边界颜色、图形大小、和子区( subplot)设置
grid: 设置网格颜色和线性
legend: 设置图例和其中的文本的显示
line: 设置线条(颜色、线型、宽度等)和标记
patch: 是填充2D空间的图形对象,如多边形和圆。控制线宽、颜色和抗锯齿设置等。
savefig: 可以对保存的图形进行单独设置。例如,设置渲染的文件的背景为白色。
verbose: 设置matplotlib在执行期间信息输出,如silent、helpful、debug和debug-annoying。
xticks和yticks: 为x,y轴的主刻度和次刻度设置颜色、大小、方向,以及标签大小。

plt.figure(figsize=(7,4))      #画布大小

plt.plot(y)
plt.plot(y.cumsum())           #y的值累加
plt.plot(y,'b',lw = 1.5)       # 蓝色的线(线的粗细)
plt.plot(y.cumsum(),'ro')      #离散的点
plt.grid(True)                 #网格显示
plt.xlim(a,b)                  #设置坐标轴的最小值和最大值
plt.ylim(a,b)                  #设置坐标轴的最小值和最大值
plt.xlabel('index')
plt.ylabel('value')
plt.plot(y[:, 1],label='2st')  #图例
plt.legend(loc=0)              # 图例位置自动
plt.title('Line 2')            #标题
plt.axis('tight')              #显示x轴的全刻度
            Empty :返回 当前坐标轴限值
            off :关闭做标轴线相标签
            equal :使用等刻度
            scalcd :通过尺寸变化平衡刻度
            tight :使所有 数据可见{缩小限值)
            Image: 使所有数据可见(使用数据限值)
plt.show()                     #显示

plt.scatter(y[:, 0], y[:, 1], marker='o')   #散点图
plt.hist(y, label=['1st', '2nd'], bins=5)   #直方图
            x :列表对象 ndarray 对象
            bins: 数据组( bin )数
            range: 数据组的下界和上界
            nonned :规范化为整数1
            weights: x 轴上每个值的权重
            cumulative: 每个数据组包含较低组别的计数
            hisstype :选项(字符串): ar, barstacked, step、stepfìlled
            align: 选项(字符串): left, mid, righl
            onentatlon: 选项(字符串): horizontal, vertical
            rwideth:条块的相对宽度
            log :对数刻度
            color :每个数据集的颜色(类似数组)
            label :标签所用的字符串或者字符串序列
            stacked :堆叠多个数据集

plt.bar(np.arange(len(y)), y[:, 1], width=0.5, color='g', label='2nc')  #上下柱状图
'''

# 最简单
def line1(y):
    plt.plot(y)
    plt.title('Line 1')
    plt.show()
def line2(y):
    plt.plot(y.cumsum())
    plt.grid(True)  #增加格点
    plt.title('Line 2')
    plt.axis('tight')  # 坐标轴适应数据量
    plt.show()
def line3(y):
    plt.plot(y.cumsum())
    plt.xlim(-1,20)
    plt.ylim(np.min(y.cumsum())- 1, np.max(y.cumsum()) + 1)
    plt.show()
def line4(y):
    plt.figure(figsize=(7,4)) #画布大小
    plt.plot(y.cumsum(),'b',lw = 4.5) # 蓝色的线
    plt.plot(y.cumsum(),'ro') #离散的点
    plt.grid(True)
    plt.axis('tight')
    plt.xlabel('index')
    plt.ylabel('value')
    plt.show()
def line5(y):                        #二维数据图 y=10*2的矩阵
    plt.plot(y, lw=1.5)
    plt.plot(y, 'ro')
    plt.show()
def line6(y):
    plt.plot(y[:, 0], lw=1.5, label='1st')
    plt.plot(y[:, 1], lw=1.5, label='2st')
    plt.legend(loc=0)  # 图例位置自动
    plt.show()
def line7(y):                                          #两个y轴(左右各一个)
    fig, ax1 = plt.subplots()  # 关键代码1
    plt.plot(y[:, 0], lw=1.5, label='1st')
    plt.plot(y[:, 0], 'ro')
    plt.legend(loc=0)  # 图例位置自动

    ax2 = ax1.twinx()  # 关键代码2
    plt.plot(y[:, 1], 'g', lw=1.5, label='2nd')
    plt.plot(y[:, 1], 'ro')
    plt.legend(loc=2)
    plt.show()
def line8(y):                                         #上下子图
    plt.figure(figsize=(7, 5))
    plt.subplot(211)  # 两行一列,第一个图   =========plt.subplot(2,1,1)
    plt.plot(y[:, 0], lw=1.5, label='1st')
    plt.plot(y[:, 0], 'ro')
    plt.legend(loc=0)  # 图例位置自动

    plt.subplot(212)  # 两行一列.第二个图
    plt.plot(y[:, 1], 'g', lw=1.5, label='2nd')
    plt.plot(y[:, 1], 'ro')
    plt.legend(loc=0)
    plt.show()
def line9(y):                                      #左右子图
    plt.figure(figsize=(10, 5))
    plt.subplot(121)  # 两行一列,第一个图
    plt.plot(y[:, 0], lw=1.5, label='1st')
    plt.plot(y[:, 0], 'ro')
    plt.legend(loc=0) # 图例位置自动

    plt.subplot(122)
    plt.bar(np.arange(len(y)), y[:, 1], width=0.5, color='g', label='2nc')
    plt.legend(loc=0)
    plt.show()
def line10(y):                                          #散点图
    plt.scatter(y[:, 0], y[:, 1], marker='^')
    # plt.scatter(y[:, 1], y[:, 0], marker='8')
    plt.show()
def line11(y):                                          #直方图
    plt.hist(y, label=['1st', '2nd'], bins=5)
    plt.show()
def line12(y):                                          #直方图(堆叠)
    plt.hist(y, label=['1st', '2nd'], color=['b', 'g'], stacked=True, bins=20)
    plt.show()
def line13(y):                                          #箱型图
    fig, ax = plt.subplots(figsize=(7, 4))
    plt.boxplot(y)
    plt.setp(ax, xticklabels=['1st', '2nd'])
    plt.show()
def line14(y):                                          #颜色的散点图(可用于分类)
    # c = np.random.randint(0, 3, len(y))
    # print(c)
    # plt.scatter(y[:, 0], y[:, 1], c=c, marker='o')
    c=y[:,2]
    print(c)
    plt.scatter(y[:, 0], y[:, 1], c=c, marker='o')
    plt.colorbar()
    plt.show()

# 1. 定义积分函数
def func(x):
    return 0.5 * np.exp(x) + 1
def line15():                                          # 函数图
    # 2.定义积分区间
    a, b = 0.5, 1.5
    x = np.linspace(0, 2)
    y = func(x)
    # 3.绘制函数图形
    fig, ax = plt.subplots(figsize=(7, 5))
    plt.plot(x, y, 'b', linewidth=2)
    plt.ylim(ymin=0)
    # ---------------4.核心, 我们使用Polygon函数生成阴影部分,表示积分面积:
    Ix = np.linspace(a, b)
    Iy = func(Ix)
    verts = [(a, 0)] + list(zip(Ix, Iy)) + [(b, 0)]
    poly = Polygon(verts, facecolor='0.7', edgecolor='0.5')
    ax.add_patch(poly)
    # ----------5.用plt.text和plt.figtext在图表上添加数学公式和一些坐标轴标签。
    plt.text(0.5 * (a + b), 1, r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center', fontsize=20)
    plt.figtext(0.9, 0.075, '$x$')
    plt.figtext(0.075, 0.9, '$f(x)$')
    #------------ 6. 分别设置x,y刻度标签的位置。
    ax.set_xticks((a, b))
    ax.set_xticklabels(('$a$', '$b$'))
    ax.set_yticks([func(a), func(b)])
    ax.set_yticklabels(('$f(a)$', '$f(b)$'))

    plt.show()
def line17():                                          # 3D图
    stike = np.linspace(50, 150, 24)
    ttm = np.linspace(0.5, 2.5, 24)
    stike, ttm = np.meshgrid(stike, ttm)
    print( stike[:2])
    # stike是24*24的矩阵
    iv = (stike - 100) ** 2 / (100 * stike) / ttm
    fig = plt.figure(figsize=(9, 6))
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(stike, ttm, iv, rstride=2, cstride=2, cmap=plt.cm.coolwarm, linewidth=0.5, antialiased=True)
    ax.set_xlabel('strike')
    ax.set_ylabel('time-to-maturity')
    ax.set_zlabel('implied volatility')
    plt.show()
def line18(y):
    # 箱型图
    strike = np.linspace(50, 150, 24)
    ttm = np.linspace(0.5, 2.5, 24)
    strike, ttm = np.meshgrid(strike, ttm)

    iv = (strike - 100) ** 2 / (100 * strike) / ttm
    fig = plt.figure(figsize=(8, 5))
    ax = fig.add_subplot(111, projection='3d')
    ax.view_init(30, 60)
    ax.scatter(strike, ttm, iv, zdir='z', s=25,c='r', marker='o')
    ax.set_xlabel('strike')
    ax.set_ylabel('time-to-maturity')
    ax.set_zlabel('implied volatili ty')
    plt.show()



def main():
    y1 = np.random.standard_normal(300)                         #一维数据
    y2 = np.random.standard_normal((10, 2))                     #二维数据
    y3=np.random.standard_normal((10, 3))
    line10(y2)
main()

各种echart图:

from pyecharts import Bar
from pyecharts import EffectScatter

#柱状图
def pic1():
    bar =Bar("我的第一个图表", "这里是副标题")
    bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
    # bar.show_config()  #输出html代码
    bar.render()

# 两个商家商品对比
def pic2():
    attr=['a','b','c']
    v1 =[10, 20, 30]
    v2 =[25, 20, 15]
    bar =Bar("标记线和标记点示例")
    bar.add("商家A", attr, v1, mark_point=["average"])
    bar.add("商家B", attr, v2, mark_line=["min", "max"])
    bar.render()

    bar =Bar("x 轴和 y 轴交换")
    bar.add("商家A", attr, v1)
    bar.add("商家B", attr, v2, is_convert=True)
    bar.render()

# (带有涟漪特效动画的散点图)
def pic3():
    v1 =[10, 20, 30, 40, 50, 60]
    v2 =[25, 20, 15, 10, 60, 33]
    es =EffectScatter("动态散点图示例")
    es.add("effectScatter", v1, v2)
    es.render()
    es =EffectScatter("动态散点图各种图形示例")
    es.add("", [10], [10], symbol_size=20, effect_scale=3.5, effect_period=3, symbol="pin")
    es.add("", [20], [20], symbol_size=12, effect_scale=4.5, effect_period=4,symbol="rect")
    es.add("", [30], [30], symbol_size=30, effect_scale=5.5, effect_period=5,symbol="roundRect")
    es.add("", [40], [40], symbol_size=10, effect_scale=6.5, effect_brushtype='fill',symbol="diamond")
    es.add("", [50], [50], symbol_size=16, effect_scale=5.5, effect_period=3,symbol="arrow")
    es.add("", [60], [60], symbol_size=6, effect_scale=2.5, effect_period=3,symbol="triangle")
    es.render()

def pic4():
    from pyecharts import Funnel
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    value = [20, 40, 60, 80, 100, 120]
    funnel = Funnel("漏斗图示例")
    funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff")
    funnel.render()
def pic5():
    from pyecharts  import Gauge
    gauge = Gauge("仪表盘示例")
    gauge.add("业务指标", "完成率", 66.66)
    gauge.show_config()
    gauge.render()
def pic6():
    from pyecharts import Geo
    data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15), ("赤峰", 16), ("青岛", 18),
                     ("乳山", 18), ("金昌", 19), ("泉州", 21), ("莱西", 21), ("日照", 21), ("胶南", 22), ("南通", 23), ("拉萨", 24),
                     ("云浮", 24), ("梅州", 25)]
    geo = Geo("全国主要城市空气质量", "data from pm2.5", title_color="#fff", title_pos="center", width=1200, height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    geo.add("", attr, value, visual_range=[0, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True)
    geo.show_config()
    geo.render()
def pic7():
    from pyecharts import Geo
    data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)]
    geo = Geo("全国主要城市空气质量", "data from pm2.5", title_color="#fff", title_pos="center", width=1200, height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    geo.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5)
    geo.show_config()
    geo.render()
# 关系图
def pic8():
    from pyecharts import Graph
    nodes = [{"name": "结点1", "symbolSize": 10}, {"name": "结点2", "symbolSize": 20},
                        {"name": "结点3", "symbolSize": 30}, {"name": "结点4", "symbolSize": 40},
                        {"name": "结点5", "symbolSize": 50}, {"name": "结点6", "symbolSize": 40},
                        {"name": "结点7", "symbolSize": 30}, {"name": "结点8", "symbolSize": 20}]
    links = []
    for i in nodes:
        for j in nodes:
            links.append({"source": i.get('name'), "target": j.get('name')})
    graph = Graph("关系图-环形布局示例")
    graph.add("", nodes, links, is_label_show=True, repulsion=8000, layout='circular', label_text_color=None)
    graph.show_config()
    graph.render()
def pic9():
    from pyecharts import Graph
    import json
    with open("..jsonweibo.json", "r", encoding="utf-8")as f:
        j = json.load(f)
    nodes, links, categories, cont, mid, userl = j
    graph = Graph("微博转发关系图", width=1200, height=600)
    graph.add("", nodes, links, categories, label_pos="right", repulsion=50, is_legend_show=False, line_curve=0.2,
              label_text_color=None)
    graph.show_config()
    graph.render()
def pic10():   #折线图(阶梯图)
    from pyecharts     import Line
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 10, 100]
    v2 = [55, 60, 16, 20, 15, 80]
    line = Line("折线图示例")
    line.add("商家A", attr, v1, mark_point=["average"])
    line.add("商家B", attr, v2, is_smooth=True, mark_line=["max", "average"])
    line.show_config()
    line.render()
    line = Line("折线图-阶梯图示例")
    line.add("商家A", attr, v1, is_step=True, is_label_show=True)
    line.show_config()
    line.render()
def pic11():
    from pyecharts     import Line
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 10, 100]
    v2 = [55, 60, 16, 20, 15, 80]
    line = Line("折线图-面积图示例")
    line.add("商家A", attr, v1, is_fill=True, line_opacity=0.2, area_opacity=0.4, symbol=None)
    line.add("商家B", attr, v2, is_fill=True, area_color='#000', area_opacity=0.3, is_smooth=True)
    line.show_config()
    line.render()
def pic12():
    from pyecharts   import Liquid
    liquid = Liquid("水球图示例")
    liquid.add("Liquid", [0.6])
    liquid.show_config()
    liquid.render()
def pic13():
    from pyecharts    import Liquid
    liquid = Liquid("水球图示例")
    liquid.add("Liquid", [0.6, 0.5, 0.4, 0.3], is_liquid_outline_show=False)
    liquid.show_config()
    liquid.render()
def pic14():    #方形水型图
    from pyecharts    import Liquid
    liquid = Liquid("水球图示例")
    liquid.add("Liquid", [0.6, 0.5, 0.4, 0.3], is_liquid_animation=False, shape='diamond')
    liquid.show_config()
    liquid.render()

def pic15():
    from pyecharts    import Map
    value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]
    attr = ["福建", "山东", "北京", "上海", "甘肃", "新疆", "河南", "广西", "西藏"]
    map = Map("Map 结合 VisualMap 示例", width=1200, height=600)
    map.add("", attr, value, maptype='china', is_visualmap=True, visual_text_color='#000')
    map.show_config()
    map.render()
def pic16():
    from pyecharts  import Map
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='广东', is_visualmap=True, visual_text_color='#000')
    map.show_config()
    map.render()
def pic17():
    # Parallel(平行坐标系)
    from pyecharts  import Parallel
    c_schema = [{"dim": 0, "name": "data"}, {"dim": 1, "name": "AQI"}, {"dim": 2, "name": "PM2.5"},
                              {"dim": 3, "name": "PM10"}, {"dim": 4, "name": "CO"}, {"dim": 5, "name": "NO2"},
                              {"dim": 6, "name": "CO2"}, {"dim": 7, "name": "等级", "type": "category",
                                                          "data": ['', '', '轻度污染', '中度污染', '重度污染', '严重污染']}]
    data = [[1, 91, 45, 125, 0.82, 34, 23, ""], [2, 65, 27, 78, 0.86, 45, 29, ""], [3, 83, 60, 84, 1.09, 73, 27, ""],
            [4, 109, 81, 121, 1.28, 68, 51, "轻度污染"], [5, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
            [6, 109, 81, 121, 1.28, 68, 51, "轻度污染"], [7, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
            [8, 89, 65, 78, 0.86, 51, 26, ""], [9, 53, 33, 47, 0.64, 50, 17, ""], [10, 80, 55, 80, 1.01, 75, 24, ""],
            [11, 117, 81, 124, 1.03, 45, 24, "轻度污染"], [12, 99, 71, 142, 1.1, 62, 42, ""],
            [13, 95, 69, 130, 1.28, 74, 50, ""], [14, 116, 87, 131, 1.47, 84, 40, "轻度污染"]]
    parallel = Parallel("平行坐标系-用户自定义指示器")
    parallel.config(c_schema=c_schema)
    parallel.add("parallel", data)
    parallel.show_config()
    parallel.render()
def pic18():
    # Pie(饼图)
    from pyecharts import Pie
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例")
    pie.add("", attr, v1, is_label_show=True)
    pie.show_config()
    pie.render()
def pic19():          #玫瑰图
    from pyecharts  import Pie
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    v2 = [19, 21, 32, 20, 20, 33]
    pie = Pie("饼图-玫瑰图示例", title_pos='center', width=900)
    pie.add("商品A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius')
    pie.add("商品B", attr, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False,
            is_label_show=True)
    pie.show_config()
    pie.render()
def pic20():
    # Polar(极坐标系)
    from pyecharts    import Polar
    radius = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    polar = Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
    polar.add("A", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barRadius', is_stack=True)
    polar.add("B", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barRadius', is_stack=True)
    polar.add("C", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barRadius', is_stack=True)
    polar.show_config()
    polar.render()
def pic21():
    from pyecharts    import Polar
    radius = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    polar = Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
    polar.add("", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barAngle', is_stack=True)
    polar.add("", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barAngle', is_stack=True)
    polar.add("", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barAngle', is_stack=True)
    polar.show_config()
    polar.render()
def pic22():   #雷达图
    from pyecharts    import Radar
    schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)]
    v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
    v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
    radar = Radar()
    radar.config(schema)
    radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True)
    radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False)
    radar.show_config()
    radar.render()
def pic23():
    from pyecharts import Radar
    value_bj = [[55, 9, 56, 0.46, 18, 6, 1], [25, 11, 21, 0.65, 34, 9, 2], [56, 7, 63, 0.3, 14, 5, 3],
                [33, 7, 29, 0.33, 16, 6, 4]]
    value_sh = [[91, 45, 125, 0.82, 34, 23, 1], [65, 27, 78, 0.86, 45, 29, 2], [83, 60, 84, 1.09, 73, 27, 3],
                [109, 81, 121, 1.28, 68, 51, 4]]
    c_schema = [{"name": "AQI", "max": 300, "min": 5}, {"name": "PM2.5", "max": 250, "min": 20},
                {"name": "PM10", "max": 300, "min": 5}, {"name": "CO", "max": 5}, {"name": "NO2", "max": 200},
                {"name": "SO2", "max": 100}]
    radar = Radar()
    radar.config(c_schema=c_schema, shape='circle')
    radar.add("北京", value_bj, item_color="#f9713c", symbol=None)
    radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None)
    radar.show_config()
    radar.render()
def pic24():
    # Scatter(散点图)                 可以用于化图形
    from pyecharts    import Scatter
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [10, 20, 30, 40, 50, 60]
    scatter = Scatter("散点图示例")
    scatter.add("A", v1, v2)
    scatter.add("B", v1[::-1], v2)
    scatter.show_config()
    scatter.render()
def pic25():    #散点图打印pyecharts子体
    from pyecharts  import Scatter
    scatter = Scatter("散点图示例")
    v1, v2 = scatter.draw("../images/pyecharts-0.png")
    scatter.add("pyecharts", v1, v2, is_random=True)
    scatter.show_config()
    scatter.render()
def pic26():
    # WordCloud(词云图)
    from pyecharts    import WordCloud
    name = ['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
                           'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
                           'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora',
                           'Serena Williams', 'NCAA baseball tournament', 'Point Break']
    value = [10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273,
             265]
    wordcloud = WordCloud(width=1300, height=620)
    wordcloud.add("", name, value, word_size_range=[20, 100])
    wordcloud.show_config()
    wordcloud.render()
def pic27():
    from pyecharts    import WordCloud
    name = ['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
                           'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
                           'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora',
                           'Serena Williams', 'NCAA baseball tournament', 'Point Break']
    value = [10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273,
             265]
    wordcloud = WordCloud(width=1300, height=620)
    wordcloud.add("", name, value, word_size_range=[30, 100], shape='diamond')
    wordcloud.show_config()
    wordcloud.render()
# def pic28():   #自定义图表
#     from pyecharts     import Bar, Line
#     attr = ['A', 'B', 'C', 'D', 'E', 'F']
#     v1 = [10, 20, 30, 40, 50, 60]
#     v2 = [15, 25, 35, 45, 55, 65]
#     v3 = [38, 28, 58, 48, 78, 68]
#     bar = Bar("Line - Bar 示例")
#     bar.add("bar", attr, v1)
#     line = Line()
#     line.add("line", v2, v3)
#     bar.custom(line.get_series())
#     bar.show_config()
#     bar.render()
def pic29():
    # 某地最低温和最高气温折线图
    from pyecharts    import Line
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日', ]
    line = Line("折线图示例")
    line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"])
    line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"],
             yaxis_formatter="°C")
    line.show_config()
    line.render()
def pic30():
    # 饼图嵌套
    from pyecharts    import Pie
    pie = Pie("饼图示例", title_pos='center', width=1000, height=600)
    pie.add("", ['A', 'B', 'C', 'D', 'E', 'F'], [335, 321, 234, 135, 251, 148], radius=[40, 55], is_label_show=True)
    pie.add("", ['H', 'I', 'J'], [335, 679, 204], radius=[0, 30], legend_orient='vertical', legend_pos='left')
    pie.show_config()
    pie.render()
def pic31():
    import random
    from pyecharts    import Pie
    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    pie = Pie("饼图示例", width=1000, height=600)
    pie.add("", attr, [random.randint(0, 100) for i in range(6)], radius=[50, 55], center=[25, 50], is_random=True)
    pie.add("", attr, [random.randint(20, 100) for i in range(6)], radius=[0, 45], center=[25, 50], rosetype='area')
    pie.add("", attr, [random.randint(0, 100) for i in range(6)], radius=[50, 55], center=[65, 50], is_random=True)
    pie.add("", attr, [random.randint(20, 100) for i in range(6)], radius=[0, 45], center=[65, 50], rosetype='radius')
    pie.show_config()
    pie.render()
def pic32():
    from pyecharts    import Bar
    attr = ["{}月".format(i) for i in range(1, 13)]
    v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
    v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
    bar = Bar("柱状图示例")
    bar.add("蒸发量", attr, v1, mark_line=["average"], mark_point=["max", "min"])
    bar.add("降水量", attr, v2, mark_line=["average"], mark_point=["max", "min"])
    bar.show_config()
    bar.render()
def pic33():          #各类电影中"好片"所占的比例
    from pyecharts    import Pie
    pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
    pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None, )
    pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None, legend_pos='left')
    pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None)
    pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24], label_pos='center', is_label_show=True,
            label_text_color=None, is_legend_show=True, legend_top="center")
    pie.show_config()
    pie.render()

参考:

https://www.jianshu.com/p/b718c307a61c

https://www.cnblogs.com/chaoren399/p/5792168.html

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

猜你喜欢

转载自www.cnblogs.com/51python/p/10440492.html