美文网首页
matplotlib日常练习(1)

matplotlib日常练习(1)

作者: WooWoods | 来源:发表于2020-01-02 14:16 被阅读0次

    散点图

    拿鸢尾花数据集来玩

    iris = pd.read_csv('iris_dataset.csv', delimiter=',')
    # 将种名映射为数值
    iris['species'] = iris['species'].map({"setosa" : 0, "versicolor" : 1, "virginica" : 2})
    
    plt.scatter(iris.petal_length, iris.petal_width, c=iris.species)
    

    气泡图

    上面图的基础上改改就是气泡图

    plt.scatter(iris.petal_length, iris.petal_width, s=50*iris.petal_length*iris.petal_width, 
                c=iris.species, alpha=0.3)
    

    堆叠图

    x = np.array([1, 2, 3, 4, 5, 6], dtype=np.int32)
    Apr = [5, 7, 6, 8, 7, 9]
    May = [0, 4, 3, 7, 8, 9]
    June = [6, 7, 4, 5, 6, 8]
    
    labels = ["April ", "May", "June"]
    
    fig, ax = plt.subplots()
    ax.stackplot(x, Apr, May, June, labels=labels)
    ax.legend(loc=2)
    
    plt.xlabel('defect reason code')
    plt.ylabel('number of defects')
    plt.title('Product Defects - Q1 FY2019')
    

    饼图

    labels = ['SciFi', 'Drama', 'Thriller', 'Comedy', 'Action', 'Romance']
    sizes = [5, 15, 10, 20, 40, 10]   # Add upto 100%
    explode = (0, 0, 0, 0, 0.1, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')
    
    fig1, ax1 = plt.subplots()
    ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
            shadow=True, startangle=90)
    

    相关文章

      网友评论

          本文标题:matplotlib日常练习(1)

          本文链接:https://www.haomeiwen.com/subject/unfooctx.html