zoukankan      html  css  js  c++  java
  • 部分画图

    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

  • 相关阅读:
    javap,是 java printer 的缩写,是 JDK 自带的 Java 字节码分析工具
    这段代码的返回值在出现异常和不出现异常的情况下,分别应该是多少?
    strictfp 关键字修饰方法,即 strict float point (精确浮点)
    transient 修饰符修饰属性:不需要序列化的属性
    Java 中的 CAS 操作
    ReentrantLock 与 synchronized 的比较
    线程安全的实现方法:互斥同步、非阻塞同步、无同步方案
    J.U.C包的意义
    synchronized 原理
    什么场景下,使用 final、volatile、Atomic原子类、synchronized、J.U.C 包中的锁?
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12679161.html
Copyright © 2011-2022 走看看