在 mplfinance 中找到 seq_col 的颜色列表以绘制线条

find list of colors in mplfinance for seq_col to draw lines

在文档中找不到任何内容: https://pypi.org/project/mplfinance/

需要绘制不同颜色的线条,只找到这些颜色代码:

'b','r','c','k','g'

再多一些颜色就更好了 - 在文档中找不到列表。

最好有人能指定rgb代码。

我的意思是,例如这一行:

剧情:

    mpf.plot(df_history, show_nontrading=True, figratio=(10,7), figscale=2, datetime_format='%d.%m.%y', #figscale=2
             xrotation=90, tight_layout=False, xlim=(xmin, xmax), ylim=(chart_unten, chart_oben),
             alines=dict(alines=seq_of_points, colors=seq_of_colors, linestyle='-', linewidths=1),
             type='candle', savefig=bildpfad, addplot=apdict, style=s, title=chart_title,
             update_width_config=dict(candle_linewidth=0.5))

试试这个:

import matplotlib.cm as cm
import numpy as np

colors = cm.rainbow(np.linspace(0, 1, arr.shape[0]))
plt.scatter(arr, arr, c=colors)

你的情况:

import matplotlib.cm as cm

seq_of_colors = cm.rainbow(np.linspace(0, 1, df_history.shape[0]))

根据官方参考中的示例,我编写了使用其颜色自定义 Seaborn 的代码。 official reference 可以在这里找到,并且由于支持十六进制格式,因此可以使用多种方法。

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import seaborn as sns
import mplfinance as mpf

color_palette = sns.color_palette("husl", 3)
colors = [mcolors.to_hex(c) for c in color_palette] 

df = pd.read_csv('./data/yahoofinance-SPY-20080101-20180101.csv',index_col=0,parse_dates=True)
df = df.loc['2016-05-01':'2016-06-16',:]

seq_of_seq_repeat_point_in_between=[
    [('2016-05-02',207),('2016-05-06',204)],
    [('2016-05-06',204),('2016-05-10',208.5),('2016-05-19',203.5),('2016-05-25',209.5)],
    [('2016-05-25',209.5),('2016-06-08',212),('2016-06-16',207.5)]]
    
mpf.plot(df,
         type='candle',style='charles',
         alines=dict(alines=seq_of_seq_repeat_point_in_between,
                     colors=colors,
                     linewidths=4,
                     alpha=0.7),
         figscale=1.25
        )