zoukankan      html  css  js  c++  java
  • Matplotlib调用imshow()函数绘制热图

    #多图显示

    import numpy as np 

    from pylab import *
    from matplotlib import pyplot as plt

    x = [1, 2, 3, 4]
    y = [3, 5, 10, 25]

    #Figure
    fig = plt.figure()

    #create(subplot)
    ax1 = fig.add_subplot(231)
    plt.plot(x, y, marker='D') #
    plt.sca(ax1)

    ax2 = fig.add_subplot(232)
    plt.scatter(x, y, marker='s', color='r')
    plt.sca(ax2)
    plt.grid(True)

    ax3 = fig.add_subplot(233)
    plt.bar(x, y, 0.5, color='c') #
    plt.sca(ax3)

    ax4 = fig.add_subplot(234)
    #
    mean = 0 #
    sigma = 1 #
    data = mean+sigma*np.random.randn(10000)
    plt.hist(data,40,normed=1,histtype='bar',facecolor='yellowgreen',alpha=0.75)
    plt.sca(ax4)

    m = np.arange(-5.0, 5.0, 0.02)
    n = np.sin(m)
    ax5 = fig.add_subplot(235)
    plt.plot(m, n)
    plt.sca(ax5)

    ax6 = fig.add_subplot(236)
    xlim(-2.5, 2.5) #
    ylim(-1, 1) #
    plt.plot(m, n)
    plt.sca(ax6)
    plt.grid(True)

    plt.show()

    #image显示

    #coding=utf-8
    from matplotlib import pyplot as plt

    X = [[1,2],[3,4]]

    fig = plt.figure()
    ax = fig.add_subplot(231)
    ax.imshow(X)

    ax = fig.add_subplot(232)
    ax.imshow(X, cmap=plt.cm.gray) #灰度

    ax = fig.add_subplot(233)
    im = ax.imshow(X, cmap=plt.cm.spring) #春
    plt.colorbar(im)

    ax = fig.add_subplot(234)
    im = ax.imshow(X, cmap=plt.cm.summer)
    plt.colorbar(im, cax=None, ax=None, shrink=0.5) #长度为半

    ax = fig.add_subplot(235)
    im = ax.imshow(X, cmap=plt.cm.autumn)
    plt.colorbar(im, shrink=0.5, ticks=[-1,0,1])

    ax = fig.add_subplot(236)
    im = ax.imshow(X, cmap=plt.cm.winter)
    plt.colorbar(im, shrink=0.5)

    plt.show()

  • 相关阅读:
    git之clone
    gulp之sass 监听文件,自动编译
    cat命令
    centos安装yum源
    centos下wget: command not found的解决方法
    centos安装
    为什么很多公司招聘前端开发要求有 Linux / Unix 下的开发经验?
    ASP.NET MVC HtmlHelper用法集锦
    Html.Listbox的用法(实例)
    JSON入门实例
  • 原文地址:https://www.cnblogs.com/pzf9266/p/8967416.html
Copyright © 2011-2022 走看看