I'm trying to copy an image of a matplotlib graph from python into Excel using xlwings. I am able to successfully do this but the image is too large once copied over to Excel. I've tried to change the size of the image using the 'height' and 'width' properties of the pictures() function in xlwings but this doesn't adjust the image. Below is my code for the graph in python and the code to paste it in Excel.
import xlwings as xw
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
graphsht = xw.books.active.sheets('Graphs')
#Import data
data = pd.read_excel(open('Test_Data.xlsx', 'rb'), index_col=0)
fig = plt.figure(figsize=(9,7))
x = pdf.plot(lw=2, label='PDF', legend=True)
data.plot(kind='hist', bins=50, density=True, alpha=0.5, label='Data', legend=True, ax=ax)
plt.title('Distribution')
#Output histogram to workbook
graphsht.pictures.add(fig, name='Distribution',left=graphsht.range('B2').left, top=graphsht.range('B2').top, height=250, width=300)
If I adjust the figsize, this does change the size of the image outputted to Excel, but the font size of the title and axes title stays exactly the same and again looks too large.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…