gpt4 book ai didi

python - 如何使用mpl_finance设置一根烛台颜色?

转载 作者:行者123 更新时间:2023-12-03 23:17:50 24 4
gpt4 key购买 nike

这是代码:

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')

这是输出:

enter image description here

我想把中间的一个改成橙色。我怎样才能找出刻度并改变它的颜色?谢谢。

最佳答案

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")

enter image description here

关于python - 如何使用mpl_finance设置一根烛台颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46326151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com