问题描述
在文档中找不到任何内容: 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))
解决方法
从官方参考中的示例中,我编写了使用颜色自定义 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
)
,
试试这个:
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,df_history.shape[0]))