In [1]:
import numpy as np
print(np.__version__)
import matplotlib.pyplot as plt
%matplotlib inline


1.13.0

In [2]:
vector = np.array([1,2,3,4,5])

In [3]:
print(vector)
print(vector.shape)


[1 2 3 4 5]
(5,)

In [4]:
vector2 = np.arange(1,6)

In [5]:
print(vector2)
print(vector2.shape)


[1 2 3 4 5]
(5,)

In [6]:
matrix = np.array([[1,2,3],[4,5,6]])
print(matrix)
print(matrix.shape)


[[1 2 3]
 [4 5 6]]
(2, 3)

In [7]:
np.random.seed(200)

In [8]:
np.random.normal(0,1,(3,5))


Out[8]:
array([[-1.45094825,  1.91095313,  0.71187915, -0.24773829,  0.36146623],
       [-0.03294967, -0.22134672,  0.47725678, -0.69193937,  0.79200593],
       [ 0.07324913,  1.30328603,  0.21348149,  1.01734895,  1.91171178]])

In [9]:
data = np.random.normal(0,1,10000)

In [10]:
print(data.shape)


(10000,)

In [11]:
plt.hist(data, bins=30,histtype='bar',color='red', alpha=0.5)
plt.show()



In [12]:
data2 = np.random.normal(0, 2, 10000)

plt.hist([data, data2], bins=50, histtype='stepfilled', color=['skyblue', 'orange'], alpha=0.7,
        label=['sigma=1', 'sigma=2'])
plt.legend(loc=0)
plt.show()



In [14]:
data = np.random.normal(0,2,1000)

In [26]:
plt.hist(data,bins=50,color="crimson")
plt.show()



In [40]:
colors = ['red',
          'crimson',
          'tomato',
          'wheat',
          'yellowgreen',
          'orange',
          'navy',
          'chartreuse',
          'green'
         ]

In [41]:
for i in colors:
    plt.hist(data,bins=50, color=i)
    plt.show()
    plt.close()



산포도 그래프 그리기


In [42]:
numPts = 2000

In [43]:
aX = np.random.normal(1,1,numPts)
aY = np.random.normal(1,1,numPts)

In [51]:
plt.scatter(aX,aY, color="blue", alpha=0.3)
plt.show()
plt.close()



In [52]:
b = np.random.normal(5,2,(numPts,2))

In [53]:
plt.scatter(b[:,0],b[:,1], color="red", alpha=0.3)
plt.show()
plt.close()



In [57]:
plt.figure(figsize=(6,6))
plt.scatter(aX, aY, color='r', s=2, alpha=0.3)
plt.scatter(b[:,0], b[:,1], color='b', s=2, alpha=0.3)
plt.show()



In [58]:
plt.figure(figsize=(6,6))
plt.scatter(aX, aY, color='k', s=2, alpha=0.3)
plt.scatter(b[:,0], b[:,1], color='k', s=2, alpha=0.3)
ax = plt.gca()
circle1 = plt.Circle((1, 1), 1*2, color='r', lw=5, fill=False)
circle2 = plt.Circle((5, 5), 2*2, color='b', lw=5, fill=False)
ax.add_artist(circle1)
ax.add_artist(circle2)

plt.show()



In [ ]: