数据可视化

本文深入探讨了数据可视化的多种方法,包括Matplotlib、Seaborn和Pyecharts等库的使用,涵盖柱状图、散点图、折线图、饼图等多种图表类型,并提供了丰富的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import matplotlib.pyplot as plt
import math
import numpy as np
import pandas as pd
import random 
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
import seaborn as sns
from pyecharts import Liquid , Boxplot , Overlap , Timeline , Gauge , Polar , Radar , Sankey , ThemeRiver 
from pyecharts import Bar , Bar3D , Line , Pie , Scatter , Scatter3D , EffectScatter , WordCloud
from pyecharts import Funnel , Geo , Graph  , HeatMap , Kline , Line3D , Map , Parallel , Page
plt.rcParams['font.sans-serif']=['SimHei']   # 中文字体设置-黑体
plt.rcParams['axes.unicode_minus']=False     # 解决保存图像是负号'-'显示为方块的问题
plt.style.use('ggplot')

labels=['北京','天津','上海','重庆','深圳']
data_1 = []
data_2 = []
data_3 = []
for i in range(1,6):
    data_1.append(random.randint(10000,50000))
    data_2.append(random.randint(0,1000))
    data_3.append(random.randint(0,10))

x_axis=['北京','天津','上海','重庆','深圳']
y_axis=['人口','交通','物流']
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
               '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']

class Matplot:
    
    def show(self):
        plt.legend()
        plt.show()   
    
    def bar(self):
        
        plt.bar(range(1,6),data_1,
                label = 'x',
                width = 0.8,
                align = 'center',
                color = 'steelblue',
                alpha=0.8 )
        plt.title('简单垂直条形图')
        plt.xticks(range(1,6),labels)
        plt.xlabel('城市')
        plt.ylabel('城市人口')
        plt.ylim([30000,60000])
        self.show()

    def barh(self):
        
        plt.barh(range(1,6),data_1,
                 label = 'x',
                 height = 0.8,
                align = 'center',
                 color = 'steelblue',
                 alpha=0.8 )
        plt.title('简单水平条形图')
        plt.yticks(range(1,6),labels)
        plt.ylabel('城市')
        plt.xlabel('城市人口')
        plt.xlim([30000,60000])
        self.show()

    def bark(self):

        bar_width=0.45

        plt.bar(np.arange(5),data_1,
                label = 'one',
                width = bar_width,
                align = 'center',
                color = 'steelblue',
                alpha=0.8 )
        plt.bar(np.arange(5)+bar_width,data_2,label = 'twe',
                width = bar_width,
                align = 'center',
                color = 'indianred',
                alpha=0.7 )
        plt.title('水平交错条形图')
        plt.xticks(range(1,6),labels)
        plt.xlabel('城市')
        plt.ylabel('城市人口')
        plt.ylim([0,100000])
        self.show()

    def barxy(self):
        
        plt.bar(range(1,6),data_1,
                label = 'one',
                width = 0.45,
                align = 'center',
                color = 'steelblue',
                alpha=0.8 )
        plt.bar(range(1,6),data_2,
                label = 'twe',
                width = 0.45,
                align = 'center',
                color = 'indianred',
                alpha=0.7 ,
                bottom=data_1)
        plt.title('垂直堆叠条形图')
        plt.xticks(range(1,6),labels)
        plt.xlabel('城市')
        plt.ylabel('城市人口')
        plt.ylim([0,100000])
        self.show()

    def plot(self):

        plt.plot(range(1,6) , data_1 ,
                 linestyle='-',
                 linewidth= 2 ,
                 color= 'steelblue',
                 markersize=6 ,
                 marker='o',
                 label='one',
                 markeredgecolor='black',
                 markerfacecolor='brown')
        plt.plot(range(1,6) , data_2 ,
                 linestyle='-',
                 linewidth= 2 ,
                 color= 'red',
                 markersize=6 ,
                 marker='o',
                 label='twe',
                 markeredgecolor='m',
                 markerfacecolor='m')
        plt.title('折线图')
        plt.xticks(range(1,6),['北京','天津','上海','重庆','深圳'])
        plt.xlabel('城市')
        plt.ylabel('城市人口')
        plt.ylim([0,100000])
        self.show()    

    def pie(self):

        explode=[0.03,0.03,0.03,0.03,0.03]
        explode[data_1.index(max(data_1))]=0.1
        ##plt.figure(1, figsize=(6,6))  
        plt.pie(x=data_1,
                explode=explode,
                labels=labels,
                colors=['steelblue','orange','y','m','g'],
                autopct='%.1f%%',
                pctdistance=0.8,
                shadow=True,
                labeldistance=1.15,
                ##radius=1,
                ##wedgeprops={'linewidth':0.5 ,'edgecolor':'black'},
                ##textprops={'fontsize':12,'color':'k'},
                ##center=(2,2)
                
                )
        
        plt.axis('equal')
        ##plt.xlim(0,4)
        ##plt.ylim(0,4)
        plt.title('饼状图', bbox={'facecolor':'0.8', 'pad':5})
        plt.xticks(())
        plt.yticks(())
        plt.show()
        
    def scatter(self):

        data_1=[]
        for i in range(1,1000):
            data_1.append(random.randint(i,i+1000))
        
        plt.scatter(range(1,1000) , data_1 ,
                    s=30,
                    c='red',
                    marker='o',
                    alpha='0.9',
                    linewidth = 0.3,
                    edgecolor = 'red')
        plt.title('散点图')
        plt.ylabel('城市人口')
        plt.ylim([0,2000])
        plt.show()

    def bubble(self):

        data_4 = []
        data_5 = []
        data_6 = []
        for i in range(1,10):
            data_4.append(random.uniform(3,6))
            data_5.append(random.uniform(3,8))
            data_6.append(random.randint(40,1000))

        plt.scatter(data_4 , data_5 ,
                    s=data_6,
                    c='steelblue',
                    marker='o',
                    alpha='0.6',
                    linewidth = 0)
        plt.title('气泡图')
        plt.ylabel('城市人口')
        plt.xlim([2,7])
        plt.ylim([2,8])
        plt.show()

    def linearregression(self):  ###未完成

        data_3=np.arange(1,101)
        data_4=[]
        for i in range(1,101):
            data_4.append(random.randint(1,101))
        data_4=np.array(data_4)

        plt.scatter(data_3 , data_4 ,
                    s=30,
                    c='black',
                    marker='o',
                    alpha='0.9',
                    linewidth = 0.3,
                    edgecolor = 'red',
                    label='观测点')
        plt.title('线性回归图')
        reg = LinearRegression().fit( data_3.reshape(-1,1),
                                      data_4.reshape(-1,1) )
        pred = reg.predict(data_3.reshape(-1,1))
        plt.plot( data_1,pred,linewidth=2,label='回归线' )

        plt.ylabel(' ')
        ##plt.ylim([0,2000])
        plt.show()




class Seaborn:
    
    pass

class Pyecharts:
    
    def bar(self):
	
        data_1=[]
        data_2=[]
        for i in range(12):
            data_1.append(random.randint(10,100))
            data_2.append(random.randint(10,100))

        bar=Bar('柱状图实例','my first bar')
        bar.add('A',['北京','天津','上海','重庆','深圳','广州','西安','郑州','武汉','南京','杭州','成都'],data_1,
                bar_category_gap= '20%' ,  #柱间距
                is_stack=False,   ##是否堆叠
                is_label_show=True,  ##是否显示标签
                mark_point=['average'],  ##用标记点标记平均数
                is_convert=False,  ##交换xy轴
                xaxis_rotate=45,  ##标签旋转
                xaxis_interval=0,  ##刻度全部显示
                is_datazoom_show=True)
        bar.add('B',['北京','天津','上海','重庆','深圳','广州','西安','郑州','武汉','南京','杭州','成都'],data_2,
                bar_category_gap= '20%' ,
                is_stack=False,
                is_label_show=True,
                is_datazoom_show=True,
                mark_line=['min','max'],  ##用标记线标记最大最小值
                xaxis_rotate=45,  ##标签旋转
                color='orange')
        bar.render(r"G:\python程序\收集图片\bar_chart.html")

    def bar3d(self):

        data=[]
        a=[0,0,0]
        for i in range(5):
            for j in range(3):
                a[2]=random.randint(1,100)
                data.append(a)
                a=a[:]
                a[1]+=1
            a=[i+1,0,0]

        bar3d=Bar3D("3D柱状图实例","my first bar3d",width=1200,height=600)
        
        bar3d.add("图例",x_axis,y_axis,data,
                  is_visual=True,visual_range=[0,100],
                  is_visualmap=True,  ##通过颜色反映值的大小
                  is_label_show=True,
                  bar_category_gap= '20%' ,
                  visual_range_color=range_color,
                  grid3d_width=100,
                  grid3d_depth=90,
                  grid3d_shading="realistic",   ##阴影效果
                  is_grid3d_rotate=True,    ##主动旋转
                  grid3d_rotate_speed=10)
        
        bar3d.render(r"G:\python程序\收集图片\bar3d_chart.html")
        
    def boxplot(self):
        
        y_axis = []
        a=[]
        for i in range(5):
            for j in range(8):
                a.append(random.randint(10,100))
            y_axis.append(a)
            a=[]
	
        boxplot = Boxplot("箱型图实例")
        y_axis = boxplot.prepare_data(y_axis)   ##转换y轴数据
        boxplot.add('boxplot',x_axis,y_axis)
        boxplot.render(r"G:\python程序\收集图片\boxplot_chart.html")
        
    def scatter(self):

        scatter = Scatter("散点图实例")
        scatter.add("A",[1,2,3,4,5],data_1,
                    ##symbol_size=10,  ##散点大小
                    visualmap=False,  ##通过颜色反映值的大小
                    visual_type='size',  ##通过散点大小反映值的大小
                    visual_range_type=[10,800]  ##调节大小区间
                    )
        scatter.render(r"G:\python程序\收集图片\scatter_chart.html")
        
    def scatter3d(self):

        data = [[random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)] for _ in range(80)]
        
        scatter3d = Scatter3D("3D散点图实例","my first scatter3d",width=1200,height=600)
        scatter3d.add("A",data,
                ##symbol_size=10,  ##散点大小
                is_visualmap=True,  ##通过颜色反映值的大小
                visual_range_color=range_color,
                ##is_visual=True,
                ##visual_range=[0,4500],
                is_label_show=False,
                grid3d_width=100,
                grid3d_depth=90,
                is_grid3d_rotate=True,    ##主动旋转
                grid3d_rotate_speed=10)
        scatter3d.render(r"G:\python程序\收集图片\scatter3d_chart.html")

    def gauge(self):

        gauge = Gauge("仪表盘图形")  
        gauge.add("重大项目", "投资占比", random.randint(10,100))  
        gauge.render(r"G:\python程序\收集图片\gauge_chart.html")  

    def liquid(self):
  
        liquid = Liquid("水球图")  
        liquid.add("Liquid",[0.8, 0.5, 0.4, 0.3],
                   is_liquid_animation=False,
                   shape='diamond')   ##shape = 'diamond'
        liquid.render(r"G:\python程序\收集图片\liquid_chart.html") 


    def es(self):
        es = EffectScatter("动态散点图各种图形示例")  
        es.add("A", [10], [10], symbol_size=20, effect_scale=3.5, effect_period=3, symbol="pin")  
        es.add("B", [20], [20], symbol_size=12, effect_scale=4.5, effect_period=4, symbol="rect")  
        es.add("C", [30], [30], symbol_size=30, effect_scale=5.5, effect_period=5, symbol="roundRect")  
        es.add("D", [40], [40], symbol_size=10, effect_scale=6.5, effect_brushtype='fill', symbol="diamond")  
        es.add("E", [50], [50], symbol_size=16, effect_scale=5.5, effect_period=3, symbol="arrow")  
        es.add("F", [60], [60], symbol_size=16, effect_scale=5.5, effect_period=3, symbol="triangle")  
        es.render(r"G:\python程序\收集图片\effectscatter_chart.html")  

    def radar(self):
     
        schema = [ ("销售", 6500),
                   ("管理", 16000),
                   ("信息技术", 30000),
                   ("客服", 38000),
                   ("研发", 52000),
                   ("市场", 25000)]
        v1 = [[3300, 10000, 28000, 35000, 50000, 19000]]
        v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
        radar = Radar("雷达图")
        radar.config(schema)
        radar.add("预算分配", v1,
                  shape='circle',
                  is_splitline=True,
                  is_axisline_show=True,
                  radar_text_color='#333',
                  radar_text_size=30,
                  is_area_show=True)
        radar.add("实际开销", v2,
                  shape='circle',
                  is_splitline=True,
                  is_axisline_show=True,
                  label_color=["#4e79a7"],
                  is_area_show=True)
        radar.render(r"G:\python程序\收集图片\radar_chart.html")

    def funnel(self):

        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(r"G:\python程序\收集图片\funnel_chart.html")

    def geo(self):
        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, 30],
                visual_text_color="#fff",
                symbol_size=15,
                is_visualmap=True)
        
        data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)]
        attr, value = geo.cast(data)
        geo.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5)

        geo.render(r"G:\python程序\收集图片\geo_chart.html")


    def map_(self):

        value =[2, 60, 2, 6, 80, 2, 5, 2, 1, 4, 5, 1,  
                4, 1, 5, 2, 2, 5, 4, 1, 1, 10, 2]  
        attr =["安徽", "北京", "福建", "广东", "贵州", "海南", "河北", "河南", "黑龙江",  
               "湖北", "湖南", "吉林", "江苏", "辽宁", "山东", "山西", "陕西", "上海",  
               "四川", "天津", "云南", "浙江", "重庆"]  
        map_=Map("地图实例","各省微信好友分布",
                 width=1200, height=600)  
        map_.add("", attr, value,
                 maptype='china',
                 is_visualmap=True,  
                visual_text_color='#000')  
        map_.render(r"G:\python程序\收集图片\map_chart.html")  

        value = [95, 70, 30, 45, 80,  
                 10, 25, 40, 5]  
        attr = [u'贵阳市', u'遵义市',  u'六盘水市', u'安顺市', u'毕节市',   
                u'铜仁市', u"黔东南苗族侗族自治州", u"黔南布依族苗族自治州",  
                u"黔西南布依族苗族自治州"]  
        _map = Map(u"贵州地图示例", width=1200, height=600)  
        _map.add("", attr, value, maptype=u'贵州',  
                is_visualmap=True, visual_text_color='#000')  
        _map.render(r"G:\python程序\收集图片\_map_chart.html")  

    def graph(self):

        nodes = [{"name": "结点1", "symbolSize": 1},
                 {"name": "结点2", "symbolSize": 2},
                 {"name": "结点3", "symbolSize": 3},
                 {"name": "结点4", "symbolSize": 4},
                 {"name": "结点5", "symbolSize": 5},
                 {"name": "结点6", "symbolSize": 4},
                 {"name": "结点7", "symbolSize": 3},
                 {"name": "结点8", "symbolSize": 2}]
        links = []
        for i in nodes:
            for j in nodes:
                links.append({"source": i.get('name'), "target": j.get('name')})
        graph = Graph("关系图-环形布局示例",
                      title_color="black",
                      title_pos="center",
                      width=1200, height=600)
        graph.add("", nodes, links, is_label_show=True,
                  repulsion=8000, layout='circular',
                  label_text_color=None)
        graph.render(r"G:\python程序\收集图片\graph_chart.html")

    def line(self):

        page = Page()
            
        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"],
                 is_smooth=True,
                 is_stick=False,
                 is_step=False,
                 is_fill=False,
                 is_symbol_show=True,)
        line.add("商家B", attr, v2, mark_line=["max", "average"],
                 is_smooth=True)
        page.add(line)

        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)
        page.add(line)
        
        page.render(r"G:\python程序\收集图片\line_chart.html")

    def pie(self):

        page = Page()
                
        attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
        v1 = [11, 12, 13, 10, 10, 10]
        pie = Pie("饼图示例")
        pie.add("", attr, v1, is_label_show=True)
        page.add(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)
        page.add(pie)
        
        page.render(r"G:\python程序\收集图片\pie_chart.html")


    def polar(self):

        page = Page()

        radius = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        polar = Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
        polar.add("A", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barRadius',is_legend_show=True, is_stack=True)
        polar.add("B", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barRadius',is_legend_show=True, is_stack=True)
        polar.add("C", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barRadius',is_legend_show=True, is_stack=True)
        page.add(polar)
        
        polar = Polar("", width=1200, height=600)
        polar.add("A", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barAngle',is_legend_show=True, is_stack=True)
        polar.add("B", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barAngle',is_legend_show=True, is_stack=True)
        polar.add("C", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barAngle',is_legend_show=True, is_stack=True)
        page.add(polar)
        
        page.render(r"G:\python程序\收集图片\polar_chart.html")


    def wordcloud(self):

        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.render(r"G:\python程序\收集图片\wordcloud_chart.html")

    def loveheart(self):

        data = []
        for i in range(101):
            theta = i / 100 * 360
            r = 5 * (1 + math.sin(theta / 180 * math.pi))
            data.append([r, theta])
        hour = [i for i in range(1, 25)]
        polar = Polar("爱心示例", width=1200, height=600)
        polar.add("Love", data, angle_data=hour, boundary_gap=False,start_angle=0)
        polar.render(r"G:\python程序\收集图片\loveheart_chart.html")

    def pie_pie(self):

        page=Page()

        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')
        page.add(pie)

        pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center', width=1000, height=600)
        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")
        page.add(pie)

        page.render(r"G:\python程序\收集图片\pie-pie_chart.html")

    def overlap(self):

        line=Line("Line-es实例", title_pos='center', width=1000, height=600)
        line.add("A",x_axis,data_2)
        es=EffectScatter()
        es.add("",x_axis,data_2,
               effect_scale=10)
        overlap=Overlap()
        overlap.add(line)
        overlap.add(es)
        overlap.render(r"G:\python程序\收集图片\Line-es_chart.html")

    def timeline(self):

        def f():
            data_a = []
            data_b = []
            for i in range(1,6):
                data_a.append(random.randint(100,1000))
                data_b.append(random.randint(100,500))
            return data_a,data_b

        timeline=Timeline(is_auto_play=True,timeline_bottom=0)
        data_a,data_b=f()
        bar_1=Bar("2013")
        bar_1.add("A",x_axis,data_a)
        bar_1.add("B",x_axis,data_b,legend_show=True)
        timeline.add(bar_1,"2013")
        data_a,data_b=f()
        bar_2=Bar("2014")
        bar_2.add("A",x_axis,data_a)
        bar_2.add("B",x_axis,data_b,legend_show=True)
        timeline.add(bar_2,"2014")
        data_a,data_b=f()
        bar_3=Bar("2015")
        bar_3.add("A",x_axis,data_a)
        bar_3.add("B",x_axis,data_b,legend_show=True)
        timeline.add(bar_3,"2015")
        data_a,data_b=f()
        bar_4=Bar("2016")
        bar_4.add("A",x_axis,data_a)
        bar_4.add("B",x_axis,data_b,legend_show=True)
        timeline.add(bar_4,"2016")
        data_a,data_b=f()
        bar_5=Bar("2017")
        bar_5.add("A",x_axis,data_a)
        bar_5.add("B",x_axis,data_b,legend_show=True)
        timeline.add(bar_5,"2017")
        timeline.render(r"G:\python程序\收集图片\timeline_chart.html")

if __name__=="__main__":
    # a=Matplot()
    # a.linearregression()
    # b=Seaborn()
    # b.f()
    # c=Pyecharts()
    # c.scatter3d()


    print("END")

'''
plt.figure()
#set the size of subplots
left,width=0.14,0.77
bottom,height=0.11,0.5
bottom_h=bottom+height+0.04
rect_line1=[left,bottom,width,height]
rect_line2=[left,bottom_h,width,0.3]
axbelow=plt.axes(rect_line1)
axupper=plt.axes(rect_line2)
plot1=axbelow.plot(y1,x1,'-ob',ms=3)
plot2=axupper.plot(y2,x2,'-og',ms=3)
plt.show()
'''

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


用来该表线条的属性:

线条风格linestyle或ls	描述	   线条风格linestyle或ls	描述
'-'	                实线	   ':'	                        虚线
'--'	                破折线	   'None',' ',''	        什么都不画
'-.'	                点划线


线条标记:

标记maker	描述	标记	描述
'o'	圆圈	'.'	点
'D'	菱形	's'	正方形
'h'	六边形1	'*'	星号
'H'	六边形2	'd'	小菱形
'_'	水平线	'v'	一角朝下的三角形
'8'	八边形	'<'	一角朝左的三角形
'p'	五边形	'>'	一角朝右的三角形
','	像素	'^'	一角朝上的三角形
'+'	加号	'\'	竖线
'None','',' '	无	'x'	X

颜色
可以通过调用matplotlib.pyplot.colors()得到matplotlib支持的所有颜色。

别名	颜色	别名	颜色
b	蓝色	g	绿色
r	红色	y	黄色
c	青色	k	黑色
m	洋红色	w	白色

如果这两种颜色不够用,还可以通过两种其他方式来定义颜色值:

    使用HTML十六进制字符串 color='eeefff' 使用合法的HTML颜色名字('red','chartreuse'等)。

    也可以传入一个归一化到[0,1]的RGB元祖。 color=(0.3,0.3,0.4)

很多方法可以介绍颜色参数,如title()。

plt.tilte('Title in a custom color',color='#123456')  

背景色
通过向如matplotlib.pyplot.axes()或者matplotlib.pyplot.subplot()这样的方法提供一个axisbg参数,可以指定坐标这的背景色。

subplot(111,axisbg=(0.1843,0.3098,0.3098)  




确定坐标范围
plt.axis([xmin, xmax, ymin, ymax])
上面例子里的axis()命令给定了坐标范围。

xlim(xmin, xmax)和ylim(ymin, ymax)来调整x,y坐标范围

%matplotlib inline  
import numpy as np  
import matplotlib.pyplot as plt  
from pylab import *  
x = np.arange(-5.0, 5.0, 0.02)  
y1 = np.sin(x)  
plt.figure(1)  
plt.subplot(211)  
plt.plot(x, y1)  
plt.subplot(212)  
#设置x轴范围  
xlim(-2.5, 2.5)  
#设置y轴范围  
ylim(-1, 1)  
plt.plot(x, y1)  


plt.figure()
你可以多次使用figure命令来产生多个图,其中,图片号按顺序增加。这里,要注意一个概念当前图和当前坐标。所有绘图操作仅对当前图和当前坐标有效。通常,你并不需要考虑这些事,下面的这个例子为大家演示这一细节。

import matplotlib.pyplot as plt  
plt.figure(1) # 第一张图  
plt.subplot(211) # 第一张图中的第一张子图  
plt.plot([1,2,3])  
plt.subplot(212) # 第一张图中的第二张子图  
plt.plot([4,5,6])  
plt.figure(2) # 第二张图  
plt.plot([4,5,6]) # 默认创建子图subplot(111)  
plt.figure(1) # 切换到figure 1 ; 子图subplot(212)仍旧是当前图  
plt.subplot(211) # 令子图subplot(211)成为figure1的当前图  
plt.title('Easy as 1,2,3') # 添加subplot 211 的标题  



plt.text()添加文字说明:
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')  


plt.annotate()文本注释:
在使用annotate时,要考虑两个点的坐标:
    被注释的地方xy(x, y)和插入文本的地方xytext(x, y)。1
plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
             arrowprops=dict(facecolor='black', shrink=0.05),  )  

'''

'''
Bar(柱状图/条形图)   
Bar3D(3D 柱状图)   
Boxplot(箱形图)   
EffectScatter(带有涟漪特效动画的散点图)   
Funnel(漏斗图)   
Gauge(仪表盘)   
Geo(地理坐标系)   
Graph(关系图)   
HeatMap(热力图)   
Kline(K线图)   
Line(折线/面积图)   
Line3D(3D 折线图)   
Liquid(水球图)   
Map(地图)   
Parallel(平行坐标系)   
Pie(饼图)   
Polar(极坐标系)   
Radar(雷达图)   
Sankey(桑基图)   
Scatter(散点图)   
Scatter3D(3D 散点图)   
ThemeRiver(主题河流图)   
WordCloud(词云图)  

用户自定义

Grid 类:并行显示多张图

Overlap 类:结合不同类型图表叠加画在同张图上

Page 类:同一网页按顺序展示多图

Timeline 类:提供时间线轮播多张图
'''

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值