Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:35:22+00:00 2026-06-15T01:35:22+00:00

I’ve got my Python script putting data into Excel worksheets and plotting the data

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:35:24+00:00Added an answer on June 15, 2026 at 1:35 am

    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:

    Sub Macro3()
    '
    ' Macro3 Macro
    '
    
    '
        ActiveChart.Legend.Select
        Selection.Delete
        ActiveSheet.ChartObjects("Chart 1").Activate
    End Sub
    

    Sadly, it did not record the resizing of the chart, but it did record deleting a legend. Here is the VBA translated into Python:

    chart.Legend.Delete()
    

    Luckily, Google provides us with How do I change the size or position of my chart with VBA? Translated into Python:

    chart.Parent.Height = new_height
    chart.Parent.Width = new_width
    chart.Parent.Top = v_position
    chart.Parent.Left = h_position
    

    edit: Here’s a short script doing all this under Excel 2003.

    import win32com.client
    import re
    
    xl = win32com.client.Dispatch('Excel.Application')
    xl.Visible=True
    wb = xl.Workbooks.Add()
    ws = wb.Sheets(1)
    values = [['a','b','c'],
              [ 1,  2,  3 ],
              [ 4,  5,  6 ]]
    for nrow, row in enumerate(values):
        for ncol, item in enumerate(row):
            xl.Cells(nrow+1, ncol+1).Value = item
    
    xl.Range("A1:C3").Select()
    chart = xl.Charts.Add()
    
    # chart.Legend.Delete only works while it's a chart sheet.
    # so get this done before changing the chart location!
    chart.Legend.Delete()
    
    # Excel changes the name of the chart when its location is changed.
    # The new name inserts a space between letters and numbers.
    # 'Chart1' becomes 'Chart 1'
    new_chart_name = re.sub(r'(\D)(\d)', r'\1 \2', chart.Name)
    chart.Location(2, ws.Name)
    
    # After changing the location the reference to chart is invalid.
    # We grab the new chart reference from the Shapes collection using the new name.
    # If only one chart is on sheet you can also do: chart = ws.Shapes(1)
    chart = ws.Shapes(new_chart_name)
    
    chart.Top = 1
    chart.Left = 1
    chart.Width = 500
    chart.Height = 400
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.