Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

python - Why are the properties 'height' and 'width' not adjusting the picture size in Excel through xlwings?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...