欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

matplotlib画图小技巧

程序员文章站 2022-02-05 19:28:47
...

1. import画图

import h5py
import numpy as np
import matplotlib.pyplot as plt
%pylab inline

 

2. 循环画多张图

fig,ax = plt.subplots(4,4,figsize = (20,20))
for i in range(4):
    for j in range(4):
        ax[i,j].imshow(rawA_padded[0+4*i+j],cmap=cm.Greys)

 

3. 并列画多张图

fig,ax = plt.subplots(1,2,figsize = (20,20))
ax[0].imshow(rawA_padded[0],cmap=cm.Greys)
ax[1].imshow(rawA[0],cmap=cm.Greys)

 

4. show_2d画分割结果图

def show_2d(picture, raw=None):
    m,n = picture.shape
    num = np.unique(picture)
    size = len(num)
    print("The number of nuerons is %d" % size)
    color = np.zeros([m, n, 3])
    for i in num:
        if i == 0 or i == 18446744073709551613:
            red=green=blue=0
        else:
            red = np.random.randint(255)
            green = np.random.randint(255)
            blue = np.random.randint(255)
        color[:,:,0][picture == i] = red
        color[:,:,1][picture == i] = green
        color[:,:,2][picture == i] = blue
    color = color / 255
    if raw is not None:
        plt.figure()
        plt.subplots(figsize=(10,10))
        plt.imshow(raw)
        plt.imshow(color, alpha=.8)
        plt.show()
    else:
        plt.figure()
        plt.subplots(figsize=(10,10))
        plt.imshow(color)
        plt.show()

 

相关标签: matplotlib