Re-sizing images generated by Matplotlib

I am using Matplotlib to generate a series of sub-plots within a figure. I would like the figure to re-size according to the number of sub-plots being added to the figure so that the printed image is not distorted, and am therefore using the fig.set_figheight() method to resize the figure as the last step in my code. However, the printed image in the excel workbook retains the size it had from the previous execution of the code. The correct dimensions can be obtained by right-clicking the image and selecting “Reset Picture & Size”. However, I’m curious if this can be done from the python code?

It can be done fairly easily from VBA, but I am unsure if it is possible to call a VBA macro in the same file as the python code?

When you run the Python code, the image output to the cell should take on any dimensions configured in your code. Any floating image is not a feature of the Python code itself, but rather a link to the output of your cell.

You can delete and recreate the image, or resize automatically using VBA as you mentioned, or you can avoid using floating images altogether and instead resize the cell itself so that it displays the entire image, either through merging with adjacent cells or making the row and/or column larger.

Is there any way to call the VBA macro from within the Python code? Or does the VBA macro have to be run separately?

Edit: I was able to resolve my issue by calling the VBA macro with Workbook_SheetCalculate