matplotlib / matplotlib/mplfinance

Fail to allocate bitmap

Open
#386 27 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
4.4k
Forks
678
PR merge metrics
No merged PRs in 30d

Description

Hello,

I have the following code that systematically ends up in the following error after 396 charts are saved.

**Fail to allocate bitmap

Process finished with exit code -2147483645**

I tried several combinations including with plt.close all or plt.close of the figure.
I tried with jpeg and png extensions
Although the memory does not seem to be cleaned up ( linear growth ) it does not seem to be the reason since it can fail with plenty of memory left to allocate.
I checked that it was not some kind of murky limitation of the disk, by moving the creation of the file to an NVME disk.
Also updated my graphic card drivers, because why not.
As you see I also tried to reload the module every time in the loop ( desperate move :) )

Really not sure what I am doing wrong here

I updated mplfinance to 0.12.7a17, matplotlib to 3.4.1.
Python version 3.9.2

for index in df.index :
    try :
        reload(mplfinance)
        i=i+1
      
        titleString =(df.iloc[index]['TimeStamp']).strftime('%Y-%m-%d')+' '+(df.iloc[index]['Symbol'])
        print ('processing  '+   str(index)+ ' ' + titleString)
        minRange = df.iloc[index]['ChainPosition'] - chartingDayAddition
        maxRange = df.iloc[index]['ChainPosition'] + tradeDuration + chartingDayAddition

      
        prices = pd.DataFrame(get1dDB().aggregate(pipeline=[
        {
                '$match' : {
                    'Symbol' : df.iloc[index]['Symbol'] ,
                    'ChainPosition': {
                        '$gte': minRange.item() ,
                        '$lte': maxRange.item()
                             }
                        }
         }]))


        BuyLine = prices.loc[prices['ChainPosition'] == df.iloc[index]['ChainPosition']]
        SellLine = prices.loc[prices['ChainPosition'] == (df.iloc[index]['ChainPosition'] + tradeDuration)]

        vls =[(BuyLine.TimeStamp).iloc[0].strftime('%Y-%m-%d'),(SellLine.TimeStamp).iloc[0].strftime('%Y-%m-%d')]

        prices.set_index('TimeStamp', inplace=True)
        fig = mplfinance.plot( prices, type='candle',volume=True, title=titleString, savefig=dict(fname=detailsPath+titleString+'.jpg', dpi=150), closefig=True)

        plt.close('all')
    except :
        print ('error')

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported loop using mplfinance.plot with savefig, closefig=True, and plt.close('all'), checking behavior around the 396th chart. Inspect the matplotlib and mplfinance plotting and bitmap-saving entry points involved in that path. Done means identifying the cause of the allocation failure and establishing a confirmed fix or documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.