20.python-matplotlib

#matplotlib

import matplotlib

import numpy as np
import matplotlib.pyplot as plt


def simple_line(x,y,figure_no):
    plt.figure(figure_no)
    plt.plot(x,y)
    plt.xlabel('x values')
    plt.ylabel('y values')
    plt.title('Simple Line')


def simple_dots(x,y,figure_no):
    plt.figure(figure_no)
    plt.plot(x,y,'or')
    plt.xlabel('x values')
    plt.ylabel('y values')
    plt.title('Simple Dots')

def simple_scatter(x,y,figure_no):
    plt.figure(figure_no)
    plt.scatter(x,y)
    plt.xlabel('x values')
    plt.ylabel('y values')
    plt.title('Simple Scatter')

def scatter_with_color(x,y,labels,figure_no):
    plt.figure(figure_no)
    plt.scatter(x,y,c=labels)
    plt.xlabel('x values')
    plt.ylabel('y values')
    plt.title('Scatter with color')

figure_no=1
x=np.arange(20)
y=np.array([np.power(xx,2) for xx in x])
simple_line(x,y,figure_no)

figure_no+=1
simple_dots(x,y,figure_no)

x=np.random.uniform(size=100)
y=np.random.uniform(size=100)
figure_no+=1
simple_scatter(x,y,figure_no)

labels=np.random.randint(2,size=100)
figure_no+=1
scatter_with_color(x,y,labels,figure_no)
plt.show()
posted @ 2018-03-23 15:19  wjc920  阅读(93)  评论(0编辑  收藏  举报