Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: __init__() missing 1 required positional argument: 'figure'

When I am trying to plot an interactive plot by the code follows:

import matplotlib.pyplot as plt
import PyQt5
%matplotlib qt
...
plt.plot(a_list,b_list)
plt.show()

I got error messages below:

 --------------------------------------------------------------------------- TypeError                                 Traceback (most recent call
 last) <ipython-input-49-187dd4fead7a> in <module>()
 ----> 1 plt.plot(parameters['eng_list'],np.real(conductivity))
       2 plt.plot(parameters['eng_list'],np.imag(conductivity))
       3 plt.show()

 C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(*args,
 **kwargs)    3305 @_autogen_docstring(Axes.plot)    3306 def plot(*args, **kwargs):
 -> 3307     ax = gca()    3308     # Deprecated: allow callers to override the hold state    3309     # by passing hold=True|False

 C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in gca(**kwargs)
     948     matplotlib.figure.Figure.gca : The figure's gca method.
     949     """
 --> 950     return gcf().gca(**kwargs)
     951 
     952 # More ways of creating axes:

 C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in gcf()
     584         return figManager.canvas.figure
     585     else:
 --> 586         return figure()
     587 
     588 

 C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in figure(num,
 figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
     533                                         frameon=frameon,
     534                                         FigureClass=FigureClass,
 --> 535                                         **kwargs)
     536 
     537         if figLabel:

 C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt4agg.py
 in new_figure_manager(num, *args, **kwargs)
      44     FigureClass = kwargs.pop('FigureClass', Figure)
      45     thisFig = FigureClass(*args, **kwargs)
 ---> 46     return new_figure_manager_given_figure(num, thisFig)
      47 
      48 

 C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt4agg.py
 in new_figure_manager_given_figure(num, figure)
      51     Create a new figure manager instance for the given figure.
      52     """
 ---> 53     canvas = FigureCanvasQTAgg(figure)
      54     return FigureManagerQT(canvas, num)
      55 

 C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt4agg.py
 in __init__(self, figure)
      74         if DEBUG:
      75             print('FigureCanvasQtAgg: ', figure)
 ---> 76         FigureCanvasQT.__init__(self, figure)
      77         FigureCanvasQTAggBase.__init__(self, figure)
      78         FigureCanvasAgg.__init__(self, figure)

 C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt4.py in
 __init__(self, figure)
      64 
      65         # Note different super-calling style to backend_qt5
 ---> 66         QtWidgets.QWidget.__init__(self)
      67         FigureCanvasBase.__init__(self, figure)
      68         self.figure = figure

 TypeError: __init__() missing 1 required positional argument: 'figure'

I am using jupyter notebook on a windows computer. With %matplotlib inline, everything works fine and an inline picture is generated, but with %matplotlib qt, it's not.

like image 536
Xiaoyu Liu Avatar asked Oct 17 '22 11:10

Xiaoyu Liu


1 Answers

Seems like a bug in the qt4 backend of matplotlib. Given your code it seems like you have qt5 around so you could simply use:

%matplotlib qt5
like image 149
MSeifert Avatar answered Oct 20 '22 10:10

MSeifert