• 部分画图


    import pandas as pd 
    unrate = pd.read_csv("unrate.csv")
    1.转换日期时间
        unrate["date"] = pd.to_datetime(unrate["DATE"])
    import matplotlib.pyplot as plt 
    2.画图操作
        plt.plot()
        传递 x y 轴,绘制折线图
        plt.plot(unrate["date"],unrate["values"])
    3.展示
        plt.show()
    4.对 x 轴上的标签倾斜 45 度
        plt.xticks(rotation = 45)
    5.设置 x 轴 y 轴标题
        plt.xlabel("xxx")
        plt.ylabel("xxx")
    6.设置名字
        plt.title("xxx")
    fig = plt.figure()
    7.绘制子图
        fig.add_subplot(行,列,x)
            x 表示 在第几个模块 
            fig.add_subplot(4,3,1)
    8.创建画图区域时指定大小
        fig = plt.figure((3,6))
        长为 3 宽为 6
    9.画线时指定颜色
        plt.plot(x,y,c="颜色")
    10.将每一年的数据都显示出来
        fig = plt.figure(figsize = (10,6))
        colors = ['red','blue','green','orange','black']
        # 设置颜色
        for i in range(5):
            start_index = i*12
            end_index = (i+1)*12
            # 定义开始和结束的位置
            subset = unrate[start_index:end_index]
            # 使用切片
            label = str(1948 + i)
            # 将标签 动态命名
            plt.plot(subset['month'],subset['value'],c = colors[i],label = label)
            # 进行绘制
        plt.legend(loc = 'best')
            loc = upper left 显示在左上角
        # 打印右上角的数据
        plt.show()
        # 展示
    11.柱状图:
        明确:柱与柱之间的距离,柱的高度
        高度:
            cols = ['FILM','XXX','AAA','FFF','TTT','QQQ']
            norm_reviews = reviews[cols]
            num_cols = ['A','B','C','D','E','F']
            bar_heights = norm_reviews.ix[0,num_cols].values
            # 将每一列的高度都存起来
        位置(距离 0 的距离):
            bar_positions = arange(5) + 0.75
            fig,ax = plt.subplots()
            ax.bar(bar_positions,bar_heights,0.3)
                先写位置后写距离
                0.3 表示柱的宽度
                ax.barh() 表示横着画
        plt.show()
    12.散点图
        fig,ax = plt.subplots()
            # 使用 ax 进行画图,ax 画图的轴,fig 图的样子
        ax.scatter(norm_reviews['A'],norm_reviews['B'])
        ax.set_xlabel('x')
        ax.set_ylabel('y')
        plt.show()
    
        # 使用 add_subplot 绘制子图
        fig = plt.figure(figsize = (5,10))
        ax1 = fig.add_subplot(2,2,1)
        ax2 = fig.add_subplot(2,2,2)
        ax1.scatter(x,y)
        ax1.set_xlabel('x')
        ax1.set_ylabel('y')
        ax2.scatter(x2,y2)
        ax2.set_xlabel('x')
        ax2.set_ylabel('y')
        plt.show()
    13.当存在多个值时,可以指定区间进行画图
        # 指定 bins 默认为 10
        fig,ax = plt.subplots()
        ax.hist(unrate['Price'],bins = 20)
        ax.hist(unrate['Price'],range(4,5),bins = 20)
    14.设置 x y 区间
        sey_xlim(0,50)
        set_ylim(0,50)
    15.盒图:
        num_cols = ['AA','BB','CC','DD']
        fig,ax = plt.subplots()
        ax.boxplot(norm_reviews[num_cols].values)
        # 绘制盒图
        ax.set_xticklabels(num_cols,rotation = 45)
        # 设置 x 轴标签,并倾斜45度
        ax.set_ylim(0,5)
        # 设置 y 的区间
        plt.show()
    16.去掉图标后的尺
        ax.tick_params(bottom = "off",top = "off",left = "off",right = "off")
    17.展示在右上角
        ax.legend(loc = "upper right")

    2020-04-11

  • 相关阅读:
    面向对象一: 数据加载器完成缓存
    软件开发模式总结
    失业求职随便接个单
    恭喜蓝网5巨头输了
    mysql安装及改端口
    解决NAVICAT 无法连接MYSQL8.0.12_可视化工具无法连接 MYSQL 8.0
    c#截取两个指定字符串中间的字符串
    匹配2关键字得结果
    怎么才能更好伪原创
    AntiCrawlerSolution(反爬解决方案)
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12679161.html
Copyright © 2020-2023  润新知