highfestiva / finplot

Performant and effortless finance plotting for Python
MIT License
919 stars 187 forks source link

Screenshot of candlestick charts - [sorry can't understand the examples given] #333

Closed hollowheights closed 2 years ago

hollowheights commented 2 years ago

I am plotting candlestick charts from a dataframe but can't save screenshots. Files are saving (as .png) but they are corrupted and can't be viewed. The plot itself shows just fine and I have seen no errors until I tried to implement the screenshot part.

I have copied the save function from the documentation. Since it isn't explicitly called, I'm assuming the .show() method checks for any function by the name of "save" and autoruns it.

fplt.candlestick_ochl(df[['open', 'close', 'high', 'low']])

def save():
        fplt.screenshot(open('screenshot2405-2.png', 'wb'))
        fplt.timer_callback(save, 0.5, single_shot=True) # wait some until we're rendered

fplt.show()

Running this in PyCharm, I get no error messages. But again, the store files are not viewable.

Maybe there is something different about screenshotting when using candlestick charts?

highfestiva commented 2 years ago

Your timer_callback() is indented, so never called.

hollowheights commented 2 years ago

I don't think that's the problem - a possible mistake when I copied it in here with bad formatting on my part. I think it runs - since the file get's created on the desk.

https://ibb.co/pZJh95h

highfestiva commented 2 years ago

You have an old file on disk. Indenting is wrong. See example line.py that takes a screenshot.

hollowheights commented 2 years ago

Thanks, Festiva! So simple and yet I had overlooked it completely. I have been looking through the examples, but don't see a way to plot in fullscreen - currently, my screenshots have low resolution.

hollowheights commented 2 years ago

I have read through this thread multiple times: https://github.com/highfestiva/finplot/issues/71 But I don't see how to close the plotting window via Python. I currently have:

def save(): fplt.screenshot(open('%s-%s.png' %(stock,date.date()), 'wb')) `

fplt.timer_callback(save, 0.5, single_shot=True) # wait some until we're rendered

fplt.show()
fplt.close()

`

highfestiva commented 2 years ago

Place the close call inside the save method.

hollowheights commented 2 years ago

Thanks, that worked indeed. I still have the problem with the size of the screenshots though. I added

fplt.winw = 1920 fplt.winh = 1080

But the plots are moving around the screen, so the saved screenshot are only partial charts. Is there perhaps a way to simply maximize the window/fullscreen mode and save a screenshot of that?

highfestiva commented 2 years ago

fplt.create_plot('My Window', maximize=True)