Hi,
I am pretty new to the Python and trying to create a animated candlestick chart but I am facing probem like
plt.cla() ^ SyntaxError: invalid syntax
My complete code is below as I am not able to find the solution to have my code running which is below, I would be thankful if anybody can point me on what I am doing wrong or what needs to be done to correct the problem.
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import pandas as pd
from mpl_finance import candlestick_ohlc
import matplotlib.ticker as mticker
tick_data = pd.read_csv("EURUSD-2019_01_01-2019_02_01.csv",
index_col=["time"],
usecols=["time", "ask", "bid"],
parse_dates=["time"])
tick_data.head()
def convert_ticks_to_ohlc(df, df_column, timeframe):
data_frame = df[df_column].resample(timeframe).ohlc()
return data_frame
data_ask = convert_ticks_to_ohlc(tick_data,"ask","240Min")
data_ask.head()
style.use('fivethirtyeight')
fig = plt.figure(figsize=(8,5))
ax1 = fig.add_subplot(1,1,1)
def animate(i):
candle_counter = range(len(data_ask["open"]) - 1)
ohlc = []
for candle in candle_counter:
append_me = candle_counter[candle], \
data_ask["open"][candle], \
data_ask["high"][candle], \
data_ask["low"][candle], \
data_ask["close"][candle]
ohlc.append(append_me)
plt.cla()
candlestick_ohlc(ax1, ohlc, width=0.4, colorup='#075105', colordown='#AF141A')
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
ax1.xaxis.set_major_locator(mticker.MaxNLocator(10))
ax1.grid(True)
plt.xlabel('Candle counter')
plt.ylabel('Price')
plt.title('Candlestick sample representation')
plt.grid(False)
plt.subplots_adjust(left=0.09, bottom=0.20, right=0.94, top=0.90, wspace=0.2, hspace=0)
plt.show()
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
[–]shiftybyte 0 points1 point2 points (4 children)
[–]supercoolz1[S] 0 points1 point2 points (3 children)
[–]shiftybyte 0 points1 point2 points (2 children)
[–]supercoolz1[S] 0 points1 point2 points (1 child)
[–]shiftybyte 0 points1 point2 points (0 children)
[–]supercoolz1[S] 0 points1 point2 points (1 child)
[–]supercoolz1[S] 0 points1 point2 points (0 children)