2017-09-20 3 views
1

Hier ist der Code:Wie setzt man eine Kerzenfarbe mit mpl_finance?

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

und hier ist die Ausgabe:

enter image description here

ich die mittleren bis orange ändern möchte. Wie kann ich den Tick herausfinden und seine Farbe ändern? Vielen Dank.

Antwort

1

Die meisten Künstler in Matplotlib haben eine .set_color() Methode.

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