I’ve got my Python script putting data into Excel worksheets and plotting the data I want on the same worksheet. Does anyone know how I can delete/hide the legend in the plot and resize the plot? Here is my code currently:
chart = xlApp.Charts.Add()
series = chart.SeriesCollection(1)
series.XValues = xlSheet.Range("L13:L200")
series.Values = xlSheet.Range("M13:M200")
series.Name = file
chart.Location(2, xlSheet.Name)
The first step in figuring out the Excel COM API is to record a macro that does what you want to do and inspect it.
I recorded a macro of me deleting the legend and resizing the chart and here is the resulting VBA:
Sadly, it did not record the resizing of the chart, but it did record deleting a legend. Here is the VBA translated into Python:
Luckily, Google provides us with How do I change the size or position of my chart with VBA? Translated into Python:
edit: Here’s a short script doing all this under Excel 2003.