Python Forum
xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet (/thread-32838.html)



xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet - KMV - Mar-09-2021

Hello,

I would like to loop into various of instrument tickers in a dataframe and plot each instrument chart into an Excel worksheet.

Is there a possibility to do that on-the-fly using xlsxwriter's "insert_image" and mplfinance's "plot" functions?

The loop looks as follows:

for ticker in ticker:
	workbook.add_worksheet(ticker) # Add multiple sheets for each instrument
	filt2 = (dfInit["Ticker"] == ticker)
	mpf.plot(dfInit[filt2], title = ticker, type = "candle", style = "classic")  # This line have to be modified in order to insert charts into excel worksheet


Thank you in advance!


RE: xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet - KMV - Mar-09-2021

I was able to insert charts into multiple sheets. However, the chart was first saved on the local drive and then inserted in spreadsheet.

for ticker in ticker:
	workbook.add_worksheet(ticker) 
	activeSheet = workbook.get_worksheet_by_name(ticker)
	filt2 = (dfInit["Ticker"] == ticker)
	mpf.plot(dfInit[filt2], title = ticker, type = "candle", style = "classic", savefig = ticker + ".png")
	activeSheet.insert_image(1, 1, ticker + ".png")
Can we do the same without saving the png to the local drive?