Mplfinance: How I can plot a list of list, without importing it from csv?

Created on 14 Apr 2020  路  3Comments  路  Source: matplotlib/mplfinance

So I have a data set list already in format of
[dataq["date"], dataq["open"], dataq["low"], dataq["high"], dataq["close"]], dataq["volume"]]
and I want to plot these,
I'm not using csv or any other file read, these are just loaded with api,
and I want to plot with new library,
how can I print thhem? it is always complaining about pandas time index,

for dataq in datalist:
    ohlc.append([pd.Timestamp(dataq["date"]), dataq["open"],
                 dataq["low"], dataq["high"], dataq["close"]])
ohlc = pd.DataFrame(ohlc)
ohlc.index.name = 'Date'
mplfinance.plot(ohlc)

I tried adding conversion to timestamp of panda but it didn't help

question

Most helpful comment

Reza,

I am assuming that ohlc is a list. Maybe try this:

ohlc = []
dates = []
for dataq in datalist:
    ohlc.append( [dataq["open"], dataq["low"], dataq["high"], dataq["close"]] )
    dates.append( pd.Timestamp( dataq["date"] ) )

dtix = pd.DatetimeIndex(dates)
ohlc = pd.DataFrame(ohlc, index=dtix, columns=['Open','Low','High','Close'] )
ohlc.index.name = 'Date'

mplfinance.plot(ohlc)

Let me know if that works. Thanks. --Daniel

All 3 comments

Reza,

I am assuming that ohlc is a list. Maybe try this:

ohlc = []
dates = []
for dataq in datalist:
    ohlc.append( [dataq["open"], dataq["low"], dataq["high"], dataq["close"]] )
    dates.append( pd.Timestamp( dataq["date"] ) )

dtix = pd.DatetimeIndex(dates)
ohlc = pd.DataFrame(ohlc, index=dtix, columns=['Open','Low','High','Close'] )
ohlc.index.name = 'Date'

mplfinance.plot(ohlc)

Let me know if that works. Thanks. --Daniel

Yes, it is works

Good to know. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattcambs picture mattcambs  路  3Comments

viorell91 picture viorell91  路  3Comments

jainraje picture jainraje  路  4Comments

Full4me picture Full4me  路  3Comments

ismailbayram picture ismailbayram  路  4Comments