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

  • SEARCH
  • Home
  • 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 5850099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:05:36+00:00 2026-05-22T13:05:36+00:00

I have a matplotlib figure on a canvas on a wxpython panel. My application

  • 0

I have a matplotlib figure on a canvas on a wxpython panel. My application is run real-time and the user can re-size the window frame. However, when this happens, the borders around my axes go out of whack.

I know I can use the function fig.subplots_adjust to adjust the borders, but the values specified in the function are percentages, so there is a TON of wasted space around the borders when maximized, even though the space is just right when the window is smaller.

Is there anything similar to this function where I can specify the border in something like pixels so that the border is the same width no matter what size the frame is?

As always, Thanks!

  • 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-05-22T13:05:37+00:00Added an answer on May 22, 2026 at 1:05 pm

    Here is an example of how this can be done. The code defines a function which translates pixel border values into percentages based on the current figure size. It also hooks up an event listener that will adjust the borders when the figure is resized:

    import numpy
    import matplotlib.pyplot as plt
    
    def adjust_borders(fig, targets):
        "Translate desired pixel sizes into percentages based on figure size."
        dpi = fig.get_dpi()
        width, height = [float(v * dpi) for v in fig.get_size_inches()]
        conversions = {
            'top': lambda v: 1.0 - (v / height),
            'bottom': lambda v: v / height,
            'right': lambda v: 1.0 - (v / width),
            'left': lambda v: v / width,
            'hspace': lambda v: v / height,
            'wspace': lambda v: v / width,
            }
        opts = dict((k, conversions[k](v)) for k, v in targets.items())
        fig.subplots_adjust(**opts)
    
    fig = plt.figure(figsize=(7, 5))
    for i in range(4):
        ax = fig.add_subplot(2, 2, i+1)
        ax.plot([1,2,3], [4,5,1])
        ax.set_xticks([])
        ax.set_yticks([])
    
    # target sizes in pixels.
    targets = dict(left=10, right=10, top=10, bottom=30, hspace=30, wspace=30)
    # hook up a function to adjust the borders when the window is resized
    fig.canvas.mpl_connect('resize_event', lambda e: adjust_borders(fig, targets))
    adjust_borders(fig, targets)
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wxPython application which contains a matplotlib panel (courtesy of wxmpl, though
I have a matplotlib figure inside of a wxmpl panel, and am trying to
I have a class that has an output() method which returns a matplotlib Figure
Say that I have two figures in matplotlib, with one plot per figure: import
Suppose I have a figure canvas with 3 plots... 2 are images of the
I have a matplotlib figure that I want to be able to switch between
I am trying to make a matplotlib figure that will have multiple horizontal boxplots
Is there a way to save a Matplotlib figure such that it can be
I have an embedded matplotlib plot in a PyQt4 application. This is the plotting
I have used Matplotlib to plot lines on a figure. Now I would now

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.