简体   繁体   中英

how to place a chart with xlwings at a particular worksheet range address from python

I am unable to position a chart at a given location on the activesheet in excel from python code shown below. I can produce the chart but cannot control the placement location on the worksheet. I am an absolute beginner and may not have followed all the required conventions in the forum. Apologies. Vas

   from __future__ import division
   get_ipython().magic(u'matplotlib inline')


   import numpy as np
   import matplotlib.pyplot as plt
   from matplotlib import rc
   from sympy import *
   from IPython.display import display as dsp
   from IPython.display import  Math, Latex
   import xlwings as xw

   plt.plot(psr,dphs)
   plot = xw.Plot(fig)
   #xlwings.shapes.shape.top = Range('A23') DID NOT WORK
   plot.show('Plot1') 

Currently, there's only a left and top position implemented in points:

plot.show('Plot1', left=10, top=30)

For xlwings >= v0.6.0, you can do:

plot.show('Plot1', left=Range('A1').left, top=Range('A1').top)

For xlwings <0.6.0, just follow the workarounds as described here :

The following shows the workaround applied to the picture object returned by the show method as alternative to setting it within the show method directly (Windows version):

pic = plot.show('Plot1')
pic.top = Range('A1').xl_range.Top
pic.left = Range('A1').xl_range.Left

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM