Category: numpy

  • numpy

    import matplotlib.pyplot as plt
    import numpy as np

    xy図
    t = np.arange(0, 5, 0.2)
    plt.plot(t, t, ‘r–‘, label=’y=x’)
    plt.plot(t, t**2, ‘bs’, label=’y=x**2′)
    plt.plot(t, t**3, ‘g^’, label=’y=x**3′)
    plt.legend()
    plt.show()

    散布図
    x = np.random.rand(50)
    y = np.random.rand(50)
    sizes = np.random.rand(50) * 100
    colors = np.random.rand(50)
    plt.scatter(x, y, s=sizes, c=colors)
    plt.show

    棒グラフ
    values = [1, 2, 3, 4, 5, 6]
    x_pos = np.arange(len(values))
    objects = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]

    plt.bar(x_pos, values)
    plt.xticks(x_pos, objects)
    plt.show()

    円グラフ
    rates = [10, 20, 30, 40]
    labels = [‘Python’, ‘C++’, ‘Ruby’, ‘Java’]
    colors = [‘red’, ‘green’, ‘yellow’, ‘blue’]

    plt.pie(rates, labels=labels, colors=colors, autopct=’%1.1f%%’)
    plt.axis(‘equal’)
    plt.show()