[Python] Wxpython with matplotlib - resize plot

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I’m using matplotlib in wxpython, and here is what I’m trying to do…

    I’d like to define my figure to be a specific (user chosen) size…say 8 inches wide by 6 inches high.

    Then, I’d like the user to be able to size the window and resize/scale the plot to fit the window, but the underlying figure still be 8x6 (to ensure fonts stay the right size and such).

    What I’m currently doing is this:

    size = self.GetClientSize()
    self.canvas.SetSize(size)
    self.figure.set_size_inches(8, 6)
    self.figure.set_dpi(min(size.width/8, size.height/6))
    # my plot configuration code is here
    self.canvas.draw_idle()


    This works great from a sizing standpoint, but if you size up the plot and back down, I end up with clutter on the right or bottom. Like this:

    [​IMG]

    Any suggestions? I saw something about wxDC.SetLogicalScale, but couldn’t figure out how to get a DC or how to custom paint the background.

    Continue reading...

Compartilhe esta Página