I'm running the following Xlwings code from the Xlwings Matplotlib & Plotly Charts tutorial.
import matplotlib.pyplot as plt
import xlwings as xw
fig = plt.figure()
plt.plot([1, 2, 3])
sheet = xw.Book().sheets[0]
sheet.pictures.add(fig, name='MyPlot', update=True)
My setup
Windows 10
Excel from Microsoft 365
Anaconda3 2024.02-1 with
python 3.11.7
xlwings 0.29.1
matplotlib 3.8.0
Expected result
When the code is typed in and run from the Anaconda Prompt (which is basically cmd.exe with customized environment variables), the figure that is pasted into the Excel worksheet has the axis and the 45-degree line etc.
Unexpected result
When the code is typed in and run from IPython or a Spyder console or a Jupyter notebook, the figure that is pasted into the Excel worksheet is blank.
QUESTION
Maybe this is a noob question, but I've not been successful in googling for a similar problem description and solution. I have read the Xlwings documentation. Is there an extra line of code that needs to be added when the code is typed out and run from a console that supports graphics instead of when typed out and run from a console that supports only character output?