在mplfinance中查找颜色列表,以便按顺序绘制线条

2024-09-24 00:20:57 发布

您现在位置:Python中文网/ 问答频道 /正文

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

需要以不同颜色绘制线条,只需使用以下颜色代码:

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

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

最好是有人能指定rgb代码

我的意思是,例如,这一行: enter image description here

情节:

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

Tags: ofhttpsorgpypi内容title颜色chart
2条回答

根据官方参考中的示例,我编写了使用Seaborn颜色定制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
        )

enter image description here

试试这个:

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)

enter image description here

就你而言:

import matplotlib.cm as cm

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

相关问题 更多 >