keisukeのブログ

***乱雑です!自分用のメモです!*** 統計や機械学習の勉強と、読み物を書く練習と、備忘録用のブログ

matplotlibのplotの種類

pyplot — Matplotlib 1.4.0 documentation

plt.plotの引数である,linestyleとcolor,markerの実際のプロット例.
plt.plot(x, y, linestyle='-', color='b', marker='.')などと指定する.
plt.plot(x, y, 'b.-')などと同時に指定もできる.

f:id:kaisk:20141016154312p:plainf:id:kaisk:20141016154315p:plain

import numpy as np
import matplotlib.pyplot as plt


linestyles = ['-', '--', '-.', ':']
markers = ['.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', '8', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_', r'$\alpha$']
colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']


def plot_plots():
    x = np.linspace(-10,10)
    data = np.sin(x)

    nof_l = len(linestyles)
    nof_m = len(markers)
    nof_c = len(colors)

    f=plt.figure()
    f.add_subplot(1,1,1, axisbg='#999999')
    plt.hold(True)
    for i in range(nof_c):
        plt.plot(x+0.5*i, data, linestyle=linestyles[i%nof_l], color=colors[i], label=colors[i]+linestyles[i%nof_l])
    legend = plt.legend(loc='best')
    legend.get_frame().set_facecolor('#999999')
    plt.savefig('plot_plots.png')
    plt.clf()

    plt.figure()
    x = np.arange(0,11,1)
    for i in range(nof_m):
        plt.plot(x, i*np.ones(len(x)), color='b', marker=markers[i], label=markers[i])
    plt.legend(loc='best', ncol=2)
    plt.ylim([-1,24])
    plt.savefig('plot_plots2.png')
    plt.clf()


if __name__ == '__main__':
    plot_plots()