wxpython panel shrinks after plot createdAdding an AuiToolbar causes “expected argument 3 type int”Why wxframe isn't raised from a function called with global gtk binder?wxPython adding frames with multiple selection optionEnableAlternateRowColours Example would help a lotPython wxWidgets : Adding components to a Panel fires an wxWindowBase::AddChild(): AddChild() called twice assertion on WindowsI want to give an event to drawn picturewxpython Post Erase Background with DCDerived panel classes in wxpythonwxpython - Erase background erases non-background componentsWxPython: Not able to load the html with WebKitCtrl.SetPageSource in MAC

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Why does the Sun have different day lengths, but not the gas giants?

Lowest total scrabble score

Argument list too long when zipping large list of certain files in a folder

How could a planet have erratic days?

Can I sign legal documents with a smiley face?

Aragorn's "guise" in the Orthanc Stone

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Intuition of generalized eigenvector.

How to explain what's wrong with this application of the chain rule?

Is it possible to have a strip of cold climate in the middle of a planet?

Why is so much work done on numerical verification of the Riemann Hypothesis?

Where does the bonus feat in the cleric starting package come from?

When were female captains banned from Starfleet?

why `nmap 192.168.1.97` returns less services than `nmap 127.0.0.1`?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

Is there a single word describing earning money through any means?

Calculating Wattage for Resistor in High Frequency Application?

If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?

Create all possible words using a set or letters

Is the U.S. Code copyrighted by the Government?

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

Is there a working SACD iso player for Ubuntu?

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?



wxpython panel shrinks after plot created


Adding an AuiToolbar causes “expected argument 3 type int”Why wxframe isn't raised from a function called with global gtk binder?wxPython adding frames with multiple selection optionEnableAlternateRowColours Example would help a lotPython wxWidgets : Adding components to a Panel fires an wxWindowBase::AddChild(): AddChild() called twice assertion on WindowsI want to give an event to drawn picturewxpython Post Erase Background with DCDerived panel classes in wxpythonwxpython - Erase background erases non-background componentsWxPython: Not able to load the html with WebKitCtrl.SetPageSource in MAC













0















I have a very simple panel, where you click a button and a plot is created (using matplotlib) and the plot is saved as a .png in my working folder.



Once the plot is created my panel shrinks in size. Does anyone know why this is?



Below is the code, and then screenshots of before and after the button is clicked.



import wx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

class MyApp(wx.App):
def __init__(self):
super().__init__(clearSigInt=True)
self.InitFrame()

def InitFrame(self):
frame = MyFrame(parent=None, title='My Frame', pos = (100,100))
frame.Show()

class MyFrame(wx.Frame):
def __init__(self, parent, title, pos):
super().__init__(parent=parent, title=title, pos=pos)
self.OnInit()

def OnInit(self):
panel = MyPanel(parent=self)

class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)

button = wx.Button(parent=self, label = "Create plot", pos = (20,80))
button.Bind(event=wx.EVT_BUTTON, handler=self.onSubmit)

def onSubmit(self,event):
ActivityDF = pd.DataFrame(
'Activity': ['A','B','C','D'],
'Count': [10,20,30,40]
)
fig, ax = plt.subplots(1)
ax.barh(ActivityDF['Activity'], ActivityDF['Count'])
fig.savefig('Figure.png',bbox_inches='tight', facecolor="None")



if __name__ == "__main__":
app = MyApp()
app.MainLoop()


Before button clicked
After button clicked










share|improve this question









New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to StackOverflow. Please add some code to your question - its much easier to help when we can reproduce the problem in a meaningful way

    – Avery
    2 days ago















0















I have a very simple panel, where you click a button and a plot is created (using matplotlib) and the plot is saved as a .png in my working folder.



Once the plot is created my panel shrinks in size. Does anyone know why this is?



Below is the code, and then screenshots of before and after the button is clicked.



import wx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

class MyApp(wx.App):
def __init__(self):
super().__init__(clearSigInt=True)
self.InitFrame()

def InitFrame(self):
frame = MyFrame(parent=None, title='My Frame', pos = (100,100))
frame.Show()

class MyFrame(wx.Frame):
def __init__(self, parent, title, pos):
super().__init__(parent=parent, title=title, pos=pos)
self.OnInit()

def OnInit(self):
panel = MyPanel(parent=self)

class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)

button = wx.Button(parent=self, label = "Create plot", pos = (20,80))
button.Bind(event=wx.EVT_BUTTON, handler=self.onSubmit)

def onSubmit(self,event):
ActivityDF = pd.DataFrame(
'Activity': ['A','B','C','D'],
'Count': [10,20,30,40]
)
fig, ax = plt.subplots(1)
ax.barh(ActivityDF['Activity'], ActivityDF['Count'])
fig.savefig('Figure.png',bbox_inches='tight', facecolor="None")



if __name__ == "__main__":
app = MyApp()
app.MainLoop()


Before button clicked
After button clicked










share|improve this question









New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to StackOverflow. Please add some code to your question - its much easier to help when we can reproduce the problem in a meaningful way

    – Avery
    2 days ago













0












0








0








I have a very simple panel, where you click a button and a plot is created (using matplotlib) and the plot is saved as a .png in my working folder.



Once the plot is created my panel shrinks in size. Does anyone know why this is?



Below is the code, and then screenshots of before and after the button is clicked.



import wx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

class MyApp(wx.App):
def __init__(self):
super().__init__(clearSigInt=True)
self.InitFrame()

def InitFrame(self):
frame = MyFrame(parent=None, title='My Frame', pos = (100,100))
frame.Show()

class MyFrame(wx.Frame):
def __init__(self, parent, title, pos):
super().__init__(parent=parent, title=title, pos=pos)
self.OnInit()

def OnInit(self):
panel = MyPanel(parent=self)

class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)

button = wx.Button(parent=self, label = "Create plot", pos = (20,80))
button.Bind(event=wx.EVT_BUTTON, handler=self.onSubmit)

def onSubmit(self,event):
ActivityDF = pd.DataFrame(
'Activity': ['A','B','C','D'],
'Count': [10,20,30,40]
)
fig, ax = plt.subplots(1)
ax.barh(ActivityDF['Activity'], ActivityDF['Count'])
fig.savefig('Figure.png',bbox_inches='tight', facecolor="None")



if __name__ == "__main__":
app = MyApp()
app.MainLoop()


Before button clicked
After button clicked










share|improve this question









New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have a very simple panel, where you click a button and a plot is created (using matplotlib) and the plot is saved as a .png in my working folder.



Once the plot is created my panel shrinks in size. Does anyone know why this is?



Below is the code, and then screenshots of before and after the button is clicked.



import wx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

class MyApp(wx.App):
def __init__(self):
super().__init__(clearSigInt=True)
self.InitFrame()

def InitFrame(self):
frame = MyFrame(parent=None, title='My Frame', pos = (100,100))
frame.Show()

class MyFrame(wx.Frame):
def __init__(self, parent, title, pos):
super().__init__(parent=parent, title=title, pos=pos)
self.OnInit()

def OnInit(self):
panel = MyPanel(parent=self)

class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)

button = wx.Button(parent=self, label = "Create plot", pos = (20,80))
button.Bind(event=wx.EVT_BUTTON, handler=self.onSubmit)

def onSubmit(self,event):
ActivityDF = pd.DataFrame(
'Activity': ['A','B','C','D'],
'Count': [10,20,30,40]
)
fig, ax = plt.subplots(1)
ax.barh(ActivityDF['Activity'], ActivityDF['Count'])
fig.savefig('Figure.png',bbox_inches='tight', facecolor="None")



if __name__ == "__main__":
app = MyApp()
app.MainLoop()


Before button clicked
After button clicked







wxpython






share|improve this question









New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago







amme













New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









ammeamme

11




11




New contributor




amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






amme is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Welcome to StackOverflow. Please add some code to your question - its much easier to help when we can reproduce the problem in a meaningful way

    – Avery
    2 days ago

















  • Welcome to StackOverflow. Please add some code to your question - its much easier to help when we can reproduce the problem in a meaningful way

    – Avery
    2 days ago
















Welcome to StackOverflow. Please add some code to your question - its much easier to help when we can reproduce the problem in a meaningful way

– Avery
2 days ago





Welcome to StackOverflow. Please add some code to your question - its much easier to help when we can reproduce the problem in a meaningful way

– Avery
2 days ago












1 Answer
1






active

oldest

votes


















0














Welcome to Stack Overflow.



First, your code is a little bit overcomplicated. There is no need to use so many classes.



Second, if you plan to use matplotlib with a GUI library then you need to import a backend so matplotlib works fine within the application you are writting.



Regarding why the panel is schrinking. I am not really sure. Perhaps an error when matplotlib tries to plot without the appropiate backend.



I simplified your code and added some comments to it.



import wx
import numpy as np

import matplotlib as mpl
## Import the matplotlib backend for wxPython
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

## Only one class is really needed in this case. There is no need to have
## a class for the App, a class for the frame and a class for the panel
class MyWin(wx.Frame):
def __init__(self, title, pos):
super().__init__(parent=None, title=title, pos=pos)

self.panel = wx.Panel(parent=self)
self.button = wx.Button(parent=self.panel, label='Create plot', pos=(20, 80))

self.button.Bind(wx.EVT_BUTTON, self.onSubmit)

def onSubmit(self, event):
x = np.arange(10)
y = np.arange(10)
## This is to work with matplotlib inside wxPython
## I prefer to use the object oriented API
self.figure = mpl.figure.Figure(figsize=(5, 5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
## This is to avoid showing the plot area. When set to True
## clicking the button show the canvas and the canvas covers the button
## since the canvas is placed by default in the top left corner of the window
self.canvas.Show(False)
self.axes.plot(x, y)
self.figure.savefig('Figure.png', bbox_inches='tight', facecolor='None')

if __name__ == '__main__':
app = wx.App()
win = MyWin('My Frame', (100, 100))
win.Show()
app.MainLoop()


Hope this helps.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    amme is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281327%2fwxpython-panel-shrinks-after-plot-created%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Welcome to Stack Overflow.



    First, your code is a little bit overcomplicated. There is no need to use so many classes.



    Second, if you plan to use matplotlib with a GUI library then you need to import a backend so matplotlib works fine within the application you are writting.



    Regarding why the panel is schrinking. I am not really sure. Perhaps an error when matplotlib tries to plot without the appropiate backend.



    I simplified your code and added some comments to it.



    import wx
    import numpy as np

    import matplotlib as mpl
    ## Import the matplotlib backend for wxPython
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

    ## Only one class is really needed in this case. There is no need to have
    ## a class for the App, a class for the frame and a class for the panel
    class MyWin(wx.Frame):
    def __init__(self, title, pos):
    super().__init__(parent=None, title=title, pos=pos)

    self.panel = wx.Panel(parent=self)
    self.button = wx.Button(parent=self.panel, label='Create plot', pos=(20, 80))

    self.button.Bind(wx.EVT_BUTTON, self.onSubmit)

    def onSubmit(self, event):
    x = np.arange(10)
    y = np.arange(10)
    ## This is to work with matplotlib inside wxPython
    ## I prefer to use the object oriented API
    self.figure = mpl.figure.Figure(figsize=(5, 5))
    self.axes = self.figure.add_subplot(111)
    self.canvas = FigureCanvas(self, -1, self.figure)
    ## This is to avoid showing the plot area. When set to True
    ## clicking the button show the canvas and the canvas covers the button
    ## since the canvas is placed by default in the top left corner of the window
    self.canvas.Show(False)
    self.axes.plot(x, y)
    self.figure.savefig('Figure.png', bbox_inches='tight', facecolor='None')

    if __name__ == '__main__':
    app = wx.App()
    win = MyWin('My Frame', (100, 100))
    win.Show()
    app.MainLoop()


    Hope this helps.






    share|improve this answer



























      0














      Welcome to Stack Overflow.



      First, your code is a little bit overcomplicated. There is no need to use so many classes.



      Second, if you plan to use matplotlib with a GUI library then you need to import a backend so matplotlib works fine within the application you are writting.



      Regarding why the panel is schrinking. I am not really sure. Perhaps an error when matplotlib tries to plot without the appropiate backend.



      I simplified your code and added some comments to it.



      import wx
      import numpy as np

      import matplotlib as mpl
      ## Import the matplotlib backend for wxPython
      from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

      ## Only one class is really needed in this case. There is no need to have
      ## a class for the App, a class for the frame and a class for the panel
      class MyWin(wx.Frame):
      def __init__(self, title, pos):
      super().__init__(parent=None, title=title, pos=pos)

      self.panel = wx.Panel(parent=self)
      self.button = wx.Button(parent=self.panel, label='Create plot', pos=(20, 80))

      self.button.Bind(wx.EVT_BUTTON, self.onSubmit)

      def onSubmit(self, event):
      x = np.arange(10)
      y = np.arange(10)
      ## This is to work with matplotlib inside wxPython
      ## I prefer to use the object oriented API
      self.figure = mpl.figure.Figure(figsize=(5, 5))
      self.axes = self.figure.add_subplot(111)
      self.canvas = FigureCanvas(self, -1, self.figure)
      ## This is to avoid showing the plot area. When set to True
      ## clicking the button show the canvas and the canvas covers the button
      ## since the canvas is placed by default in the top left corner of the window
      self.canvas.Show(False)
      self.axes.plot(x, y)
      self.figure.savefig('Figure.png', bbox_inches='tight', facecolor='None')

      if __name__ == '__main__':
      app = wx.App()
      win = MyWin('My Frame', (100, 100))
      win.Show()
      app.MainLoop()


      Hope this helps.






      share|improve this answer

























        0












        0








        0







        Welcome to Stack Overflow.



        First, your code is a little bit overcomplicated. There is no need to use so many classes.



        Second, if you plan to use matplotlib with a GUI library then you need to import a backend so matplotlib works fine within the application you are writting.



        Regarding why the panel is schrinking. I am not really sure. Perhaps an error when matplotlib tries to plot without the appropiate backend.



        I simplified your code and added some comments to it.



        import wx
        import numpy as np

        import matplotlib as mpl
        ## Import the matplotlib backend for wxPython
        from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

        ## Only one class is really needed in this case. There is no need to have
        ## a class for the App, a class for the frame and a class for the panel
        class MyWin(wx.Frame):
        def __init__(self, title, pos):
        super().__init__(parent=None, title=title, pos=pos)

        self.panel = wx.Panel(parent=self)
        self.button = wx.Button(parent=self.panel, label='Create plot', pos=(20, 80))

        self.button.Bind(wx.EVT_BUTTON, self.onSubmit)

        def onSubmit(self, event):
        x = np.arange(10)
        y = np.arange(10)
        ## This is to work with matplotlib inside wxPython
        ## I prefer to use the object oriented API
        self.figure = mpl.figure.Figure(figsize=(5, 5))
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, -1, self.figure)
        ## This is to avoid showing the plot area. When set to True
        ## clicking the button show the canvas and the canvas covers the button
        ## since the canvas is placed by default in the top left corner of the window
        self.canvas.Show(False)
        self.axes.plot(x, y)
        self.figure.savefig('Figure.png', bbox_inches='tight', facecolor='None')

        if __name__ == '__main__':
        app = wx.App()
        win = MyWin('My Frame', (100, 100))
        win.Show()
        app.MainLoop()


        Hope this helps.






        share|improve this answer













        Welcome to Stack Overflow.



        First, your code is a little bit overcomplicated. There is no need to use so many classes.



        Second, if you plan to use matplotlib with a GUI library then you need to import a backend so matplotlib works fine within the application you are writting.



        Regarding why the panel is schrinking. I am not really sure. Perhaps an error when matplotlib tries to plot without the appropiate backend.



        I simplified your code and added some comments to it.



        import wx
        import numpy as np

        import matplotlib as mpl
        ## Import the matplotlib backend for wxPython
        from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

        ## Only one class is really needed in this case. There is no need to have
        ## a class for the App, a class for the frame and a class for the panel
        class MyWin(wx.Frame):
        def __init__(self, title, pos):
        super().__init__(parent=None, title=title, pos=pos)

        self.panel = wx.Panel(parent=self)
        self.button = wx.Button(parent=self.panel, label='Create plot', pos=(20, 80))

        self.button.Bind(wx.EVT_BUTTON, self.onSubmit)

        def onSubmit(self, event):
        x = np.arange(10)
        y = np.arange(10)
        ## This is to work with matplotlib inside wxPython
        ## I prefer to use the object oriented API
        self.figure = mpl.figure.Figure(figsize=(5, 5))
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, -1, self.figure)
        ## This is to avoid showing the plot area. When set to True
        ## clicking the button show the canvas and the canvas covers the button
        ## since the canvas is placed by default in the top left corner of the window
        self.canvas.Show(False)
        self.axes.plot(x, y)
        self.figure.savefig('Figure.png', bbox_inches='tight', facecolor='None')

        if __name__ == '__main__':
        app = wx.App()
        win = MyWin('My Frame', (100, 100))
        win.Show()
        app.MainLoop()


        Hope this helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        kbr85kbr85

        428




        428






















            amme is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            amme is a new contributor. Be nice, and check out our Code of Conduct.












            amme is a new contributor. Be nice, and check out our Code of Conduct.











            amme is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281327%2fwxpython-panel-shrinks-after-plot-created%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현