本文整理匯總了Python中matplotlib.finance方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.finance方法的具體用法?Python matplotlib.finance怎麽用?Python matplotlib.finance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib
的用法示例。
在下文中一共展示了matplotlib.finance方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lPullYahooToTxtfile
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import finance [as 別名]
def lPullYahooToTxtfile(sSymbol):
'''
Use this to dynamically pull a sSymbol:
'''
try:
print 'Currently Pulling', sSymbol
print str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%Y-%m-%d %H:%M:%S'))
#Keep in mind this is close high low open, lol.
urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+sSymbol+'/chartdata;type=quote;range=10y/csv'
lStockLines = []
try:
sourceCode = urllib2.urlopen(urlToVisit).read()
splitSource = sourceCode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
if len(splitLine) == 6:
if 'values' not in eachLine:
lStockLines.append(eachLine)
return lStockLines
except Exception as e:
print str(e), 'failed to organize pulled data.'
except StandardError, e:
print str(e), 'failed to pull pricing data'
示例2: plot_p
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import finance [as 別名]
def plot_p(df):
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
fig, ax = plt.subplots()
candlestick2_ohlc(ax,
df['price_open'].values,
df['price_high'].values,
df['price_low'].values,
df['price_close'].values,
width=0.6,
colorup='g',
colordown='r',
alpha=1)
plt.show()
print('Done.')
示例3: save_to_file
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import finance [as 別名]
def save_to_file(df, filename):
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
fig, ax = plt.subplots()
candlestick2_ohlc(ax,
df['price_open'].values,
df['price_high'].values,
df['price_low'].values,
df['price_close'].values,
width=0.6,
colorup='g',
colordown='r',
alpha=1)
plt.savefig(filename)
plt.close(fig)