本文整理汇总了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)