코딩노예 [421820] · MS 2012 · 쪽지

2014-12-12 16:26:08
조회수 589

Python

게시글 주소: https://mission.orbi.kr/0005239040

# -*- coding: utf-8 -*-




import numpy as np


import pandas as pd


import matplotlib.pyplot as plt




fig = plt.figure()




ax1 = fig.add_subplot(2,2,1)


ax2 = fig.add_subplot(2,2,2)


ax3 = fig.add_subplot(2,2,3)




plt.plot(np.random.randn(50).cumsum(), 'co-')




_ = ax1.hist(np.random.randn(100), bins = 20, color = 'b', alpha = 0.3)




ax2.scatter(np.arange(30), np.arange(30)+3*np.random.randn(30))




fig, axes = plt.subplots(2, 2, sharex = True, sharey = True)



for i in range(2):


for j in range(2):


axes[i, j].hist(np.random.randn(500), bins = 50)



plt.subplots_adjust(wspace = 0.5, hspace = 0)




data = np.random.randn(30).cumsum()




plt.plot(data, 'k--', label = 'Default')


plt.plot(data, 'k-', drawstyle = 'steps-post', label = 'stemps-post')




plt.legend(loc = 'best')




a = np.arange(1, 10)


print a.cumsum()


print a.cumprod()




fig = plt.figure()


ax = fig.add_subplot(1, 1, 1)


ax.plot(np.random.randn(1000).cumsum())




ticks = ax.set_xticks([0, 250, 500, 750, 1000])


labels = ax.set_xticklabels(['one', 'two', 'three', 'four', 'five'],


rotation = 30,


fontsize = 'small')



ax.set_title('My plot')


ax.set_xlabel('Stages')


ax.set_ylabel('Values')




from datetime import datetime


import matplotlib.pylab as plt




fig = plt.figure()


ax = fig.add_subplot(1,1,1)




data = pd.read_csv('spx.csv', index_col = 0, parse_dates = True)


spx = data['SPX']




spx.plot(ax = ax, style = 'k--')




crisis_data = [


(datetime(2007,10,11), 'Peak of bull market'),


(datetime(2008, 3, 12), 'Bear Stearns Fails'),


(datetime(2008, 9, 15), 'Lehman Bankruptcy')


]




for date, label in crisis_data:


ax.annotate(label,


xy = (date, spx.asof(date)+50),


xytext = (date, spx.asof(date)+200),


arrowprops=dict(facecolor = 'black'),


horizontalalignment = 'left', verticalalignment = 'top')



ax.set_xlim(['1/1/2007', '1/1/2011'])


ax.set_ylim([600, 1800])




ax.set_title('Important dates in 2008-2009 financial crisis')


#뭔말인지 하나도 모르겠다 떤져야겠다


0 XDK (+0)

  1. 유익한 글을 읽었다면 작성자에게 XDK를 선물하세요.