Headless Screenshot with for-loop [assistance/help] #77
-
Hey Highfestiva, I originally asked my question under an issue and realized that was the wrong place to ask a question. I think the discussion board is the best place to do this. hoping my novice question will help others and myself better understand python and your finplot app. Anyways, I'm still trying to figure out how your screenshot() function works. Let me explain what I understand is happening and maybe you or someone can correct me where I'm wrong.
working in headless mode was shared here. Which I copied this example but failed to execute. I was still having to close out of my chart to proceed through the for-loop. also passing variables into Breaking down screenshot():starting at line 1598 You must use the fplt.timer_callback() function before you can use the screenshot function. IF the call back function is used, move forward (go into def screenshot(file, fmt='png'):
if _internal_windows_only() and not app:
print('ERROR: save_screenshot must be callbacked from e.g. timer_callback()')
return False
try:
buffer = QtCore.QBuffer()
app.primaryScreen().grabWindow(windows[0].winId()).save(buffer, fmt)
file.write(buffer.data())
return True
except Exception as e:
print(type(e), e)
return False This all makes sense to me and this feature is working. However, when i'm testing this function inside a for-loop I have to exit the window each time. is it possible to save a chart without using the lastly, I'm familiar with taking a screenshot in headless mode. you shared how to do so here. when using is it my misunderstanding of how to save an image? matplotlib has an option called Below is my code which WORKS but I have to exit each time to let the for-loop continue. If possible I'd like to not interact with the computer during proccessing stocks. #!/usr/local/bin/python3
import finplot as fplt
import numpy as np
import pandas as pd
import datetime as dt
import pandas_datareader.data as web
import io
company_symbol = ['SHOP', 'NET']
today = dt.date.today()
end = dt.datetime(today.year, today.month,today.day)
start = dt.datetime(today.year -1, today.month,today.day)
def save():
# f = io.BytesIO()
# fplt.screenshot(f)
# do_something(f)
fplt.screenshot(open('screenshot.png', 'wb'))
for symbol in company_symbol:
# df = web.DataReader(f'{symbol}', 'yahoo', start=start, end=end)
# df.to_csv(f'{symbol}.csv')
df = pd.read_csv(f'{symbol}.csv', parse_dates=True, index_col=0)
fplt.candlestick_ochl(df[['Open','Close','High','Low']])
# ax = fplt.create_plot(f'{symbol}', rows=1)
fplt.timer_callback(save, 0.5, single_shot=True) # wait some until we're rendered
fplt.show() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You only have to |
Beta Was this translation helpful? Give feedback.
You only have to
show()
once, then use the (timer) callbacks to update and take screenshots. Update is done through.update_data()
, see examples.