AYE89

coding & learning

导航

Python绘制2D图像

Posted on 2018-03-23 16:47  AYE89  阅读(1339)  评论(0编辑  收藏  举报

封装了一个简单的2d绘图函数

from matplotlib import pyplot as plt

def plot_line(*args, **kw):
    """
    
    :param args: x,y,...
    :param kw: name, xlabel, ylabel,...
    :return: 
    """
    name = 'line_chart'
    if 'name' in kw:
        name = kw['name']
        kw.pop('name')
    xlabel = ''
    if 'xlabel' in kw:
        xlabel = kw['xlabel']
        kw.pop('xlabel')
    ylabel = ''
    if 'ylabel' in kw:
        ylabel = kw['ylabel']
        kw.pop('ylabel')

    if 'c' and 'color' not in kw:
        kw['color'] = 'r'

    fig = plt.figure()
    plt.title(name)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.plot(*args,**kw)

    plt.grid()
    plt.show()

#import numpy as np
#a = np.arange(36)
#plot_line(a,name='chart',xlabel='count')