Python Forum
xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet
#1
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!
Reply
#2
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create simple live plot of stock data dram 2 2,921 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
  Create Excel Line Chart Programmatically dee 3 1,189 Dec-30-2022, 08:44 PM
Last Post: dee
  Changing the initial worksheet name in an MS Excel file azizrasul 3 962 Oct-02-2022, 07:56 PM
Last Post: azizrasul
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,364 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,497 Mar-09-2021, 12:24 PM
Last Post: KMV
  Python Matplotlib: Create chart for every 4 columns in Excel file JaneTan 2 2,775 Feb-28-2021, 05:02 AM
Last Post: JaneTan
  How to plot intraday data of several days in one plot mistermister 3 2,915 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  xlsxwriter in windows dfstrottersfan 2 2,341 Sep-23-2020, 11:41 AM
Last Post: dfstrottersfan
  How to plot gantt chart using matplotlib Mekala 1 2,641 Jul-16-2020, 07:21 PM
Last Post: Marbelous
  Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter jackie 1 3,205 May-27-2020, 11:47 PM
Last Post: mcmxl22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020