作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是代码:
import numpy as np
import matplotlib.pyplot as plt
import datetime
from mpl_finance import candlestick_ochl
from matplotlib.dates import num2date
%matplotlib notebook
# data in a text file, 5 columns: time, opening, close, high, low
# note that I'm using the time you formated into an ordinal float
# data = np.loadtxt('finance-data.txt', delimiter=',')
data = np.array([[1, 2, 3, 4, 1],
[2, 3, 1, 5, 1],
[3, 4, 3, 5, 2.3]
])
# determine number of days and create a list of those days
ndays = np.unique(np.trunc(data[:,0]), return_index=True)
xdays = []
for n in np.arange(len(ndays[0])):
xdays.append(datetime.date.isoformat(num2date(data[ndays[1],0][n])))
# creation of new data by replacing the time array with equally spaced values.
# this will allow to remove the gap between the days, when plotting the data
data2 = np.hstack([np.arange(data[:,0].size)[:, np.newaxis], data[:,1:]])
# plot the data
fig = plt.figure(figsize=(10, 5))
ax = fig.add_axes([0.1, 0.2, 0.85, 0.7])
# customization of the axis
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.tick_params(axis='both', direction='out', width=2, length=8,
labelsize=12, pad=8)
ax.spines['left'].set_linewidth(2)
ax.spines['bottom'].set_linewidth(2)
# set the ticks of the x axis only when starting a new day
ax.set_xticks(data2[ndays[1],0])
ax.set_xticklabels(xdays, rotation=45, horizontalalignment='right')
ax.set_ylabel('Quote ($)', size=20)
ax.set_ylim([0, 10])
drawData = candlestick_ochl(ax, data2, width=0.5, colorup='g', colordown='r')
最佳答案
matplotlib 中的大多数艺术家都有一个 .set_color()
方法。
lines, rectangles = candlestick_ochl(ax, data2, width=0.5, colorup='g', colordown='r')
lines[1].set_color("orange")
rectangles[1].set_color("orange")
关于python - 如何使用mpl_finance设置一根烛台颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46326151/
如何将mpl_finance包安装到Anaconda上的环境路径中? 我尝试了 pip install mpl_finance 但我仍然在 Anaconda 上找不到该软件包,它去了哪里?我对 Pyt
我正在使用 DataFrame。我的数据用于烛台。问题是我无法删除周末日期。我的意思是,我的代码显示了这一点: enter image description here 我正在寻找这个: enter
收到此错误消息: MatplotlibDeprecationWarning:财务模块已在 mpl 2.0 中弃用,并将在 mpl 2.2 中删除。请改用模块 mpl_finance。 我该如何安装 m
我正在尝试导入 matplotlib.finance python中的模块,以便我可以制作烛台OCHL图。我的 matplotlib.pyplot版本是 2.00。我尝试使用以下命令导入它: impo
我是一名优秀的程序员,十分优秀!