find list of colors in mplfinance for seq_col to draw lines

Viewed 566

Can't find anything in the dokumentation: https://pypi.org/project/mplfinance/

Need to draw lines in different colors, found just theese color codes:

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

A few more colors would be great - didn't find a list in the documentation.

The best would be if someone could specify the rgb code.

I mean e.g. this line: enter image description here

the plot:

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

From the sample in the official reference, I wrote the code to customize the Seaborn using its color. The official reference can be found here, and since the hex format is supported, various approaches are possible.

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

Try this:

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

In your case:

import matplotlib.cm as cm

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