Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Yori Fournier
myplotlib
Commits
2af2ac44
Commit
2af2ac44
authored
Mar 08, 2017
by
Philipp Gast
Browse files
renamed myWinQt* to examples
parent
209de922
Changes
3
Hide whitespace changes
Inline
Side-by-side
mplQt4_example.py
0 → 100644
View file @
2af2ac44
#!/usr/bin/env python
# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
# 2006 Darren Dale
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.
# source: https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html
from
__future__
import
unicode_literals
import
sys
import
os
import
random
from
matplotlib.backends
import
qt4_compat
use_pyside
=
qt4_compat
.
QT_API
==
qt4_compat
.
QT_API_PYSIDE
if
use_pyside
:
from
PySide
import
QtGui
,
QtCore
else
:
from
PyQt4
import
QtGui
,
QtCore
from
numpy
import
arange
,
sin
,
pi
from
matplotlib.backends.backend_qt4agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
progname
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
progversion
=
"0.1"
class
MyMplCanvas
(
FigureCanvas
):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def
__init__
(
self
,
parent
=
None
,
width
=
5
,
height
=
4
,
dpi
=
100
):
fig
=
Figure
(
figsize
=
(
width
,
height
),
dpi
=
dpi
)
self
.
axes
=
fig
.
add_subplot
(
111
)
# We want the axes cleared every time plot() is called
self
.
axes
.
hold
(
False
)
self
.
compute_initial_figure
()
#
FigureCanvas
.
__init__
(
self
,
fig
)
self
.
setParent
(
parent
)
FigureCanvas
.
setSizePolicy
(
self
,
QtGui
.
QSizePolicy
.
Expanding
,
QtGui
.
QSizePolicy
.
Expanding
)
FigureCanvas
.
updateGeometry
(
self
)
def
compute_initial_figure
(
self
):
pass
class
MyStaticMplCanvas
(
MyMplCanvas
):
"""Simple canvas with a sine plot."""
def
compute_initial_figure
(
self
):
t
=
arange
(
0.0
,
3.0
,
0.01
)
s
=
sin
(
2
*
pi
*
t
)
self
.
axes
.
plot
(
t
,
s
)
#~ class MyDynamicMplCanvas(MyMplCanvas):
#~ """A canvas that updates itself every second with a new plot."""
#~ def __init__(self, *args, **kwargs):
#~ MyMplCanvas.__init__(self, *args, **kwargs)
#~ timer = QtCore.QTimer(self)
#~ timer.timeout.connect(self.update_figure)
#~ timer.start(1000)
#~
#~ def compute_initial_figure(self):
#~ self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')
#~
#~ def update_figure(self):
#~ # Build a list of 4 random integers between 0 and 10 (both inclusive)
#~ l = [random.randint(0, 10) for i in range(4)]
#~
#~ self.axes.plot([0, 1, 2, 3], l, 'r')
#~ self.draw()
class
ApplicationWindow
(
QtGui
.
QMainWindow
):
def
__init__
(
self
):
QtGui
.
QMainWindow
.
__init__
(
self
)
self
.
setAttribute
(
QtCore
.
Qt
.
WA_DeleteOnClose
)
self
.
setWindowTitle
(
"application main window"
)
#~ self.file_menu = QtGui.QMenu('&File', self)
#~ self.file_menu.addAction('&Quit', self.fileQuit,
#~ QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
#~ self.menuBar().addMenu(self.file_menu)
#~
#~ self.help_menu = QtGui.QMenu('&Help', self)
#~ self.menuBar().addSeparator()
#~ self.menuBar().addMenu(self.help_menu)
#~ self.help_menu.addAction('&About', self.about)
self
.
main_widget
=
QtGui
.
QWidget
(
self
)
l
=
QtGui
.
QVBoxLayout
(
self
.
main_widget
)
sc
=
MyStaticMplCanvas
(
self
.
main_widget
,
width
=
5
,
height
=
4
,
dpi
=
100
)
#~ dc = MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100)
l
.
addWidget
(
sc
)
#~ l.addWidget(dc)
self
.
main_widget
.
setFocus
()
self
.
setCentralWidget
(
self
.
main_widget
)
#~ self.statusBar().showMessage("All hail matplotlib!", 2000)
#~ def fileQuit(self):
#~ self.close()
#~ def closeEvent(self, ce):
#~ self.fileQuit()
#~ def about(self):
#~ QtGui.QMessageBox.about(self, "About",
#~ """embedding_in_qt4.py example
#~ Copyright 2005 Florent Rougon, 2006 Darren Dale
#~
#~ This program is a simple example of a Qt4 application embedding matplotlib
#~ canvases.
#~
#~ It may be used and modified with no restriction; raw copies as well as
#~ modified versions may be distributed without limitation."""
#~ )
qApp
=
QtGui
.
QApplication
(
sys
.
argv
)
aw
=
ApplicationWindow
()
aw
.
setWindowTitle
(
"%s"
%
progname
)
aw
.
show
()
sys
.
exit
(
qApp
.
exec_
())
#qApp.exec_()
m
yWin_Qt5Agg
.py
→
m
plQt5_example
.py
View file @
2af2ac44
# source: https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html
# embedding_in_qt5.py --- Simple Qt5 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
# 2006 Darren Dale
# 2015 Jens H Nielsen
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.
#source: http://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html
from
__future__
import
unicode_literals
import
sys
import
os
import
random
import
matplotlib
matplotlib
.
use
(
"Qt5Agg"
)
from
PyQt5
import
QtCore
from
PyQt5.QtWidgets
import
QApplication
,
QMainWindow
,
QMenu
,
QVBoxLayout
,
QSizePolicy
,
QMessageBox
,
QWidget
# Make sure that we are using QT5
matplotlib
.
use
(
'Qt5Agg'
)
from
PyQt5
import
QtCore
,
QtWidgets
from
numpy
import
arange
,
sin
,
pi
from
matplotlib.backends.backend_qt5agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
progname
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
progversion
=
"0.1"
class
MyMplCanvas
(
FigureCanvas
):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def
__init__
(
self
,
parent
=
None
,
width
=
5
,
height
=
4
,
dpi
=
100
):
fig
=
Figure
(
figsize
=
(
width
,
height
),
dpi
=
dpi
)
self
.
axes
=
fig
.
add_subplot
(
111
)
# We want the axes cleared every time plot() is called
self
.
axes
.
hold
(
False
)
self
.
compute_initial_figure
()
#
FigureCanvas
.
__init__
(
self
,
fig
)
self
.
setParent
(
parent
)
FigureCanvas
.
setSizePolicy
(
self
,
QSizePolicy
.
Expanding
,
QSizePolicy
.
Expanding
)
QtWidgets
.
QSizePolicy
.
Expanding
,
QtWidgets
.
QSizePolicy
.
Expanding
)
FigureCanvas
.
updateGeometry
(
self
)
def
compute_initial_figure
(
self
):
pass
class
MyStaticMplCanvas
(
MyMplCanvas
):
"""Simple canvas with a sine plot."""
def
compute_initial_figure
(
self
):
t
=
arange
(
0.0
,
3.0
,
0.01
)
s
=
sin
(
2
*
pi
*
t
)
...
...
@@ -43,6 +59,7 @@ class MyStaticMplCanvas(MyMplCanvas):
class
MyDynamicMplCanvas
(
MyMplCanvas
):
"""A canvas that updates itself every second with a new plot."""
def
__init__
(
self
,
*
args
,
**
kwargs
):
MyMplCanvas
.
__init__
(
self
,
*
args
,
**
kwargs
)
timer
=
QtCore
.
QTimer
(
self
)
...
...
@@ -55,30 +72,31 @@ class MyDynamicMplCanvas(MyMplCanvas):
def
update_figure
(
self
):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l
=
[
random
.
randint
(
0
,
10
)
for
i
in
range
(
4
)]
self
.
axes
.
cla
()
self
.
axes
.
plot
([
0
,
1
,
2
,
3
],
l
,
'r'
)
self
.
draw
()
class
ApplicationWindow
(
QMainWindow
):
class
ApplicationWindow
(
QtWidgets
.
QMainWindow
):
def
__init__
(
self
):
QMainWindow
.
__init__
(
self
)
QtWidgets
.
QMainWindow
.
__init__
(
self
)
self
.
setAttribute
(
QtCore
.
Qt
.
WA_DeleteOnClose
)
self
.
setWindowTitle
(
"application main window"
)
self
.
file_menu
=
QMenu
(
'&File'
,
self
)
self
.
file_menu
=
QtWidgets
.
QMenu
(
'&File'
,
self
)
self
.
file_menu
.
addAction
(
'&Quit'
,
self
.
fileQuit
,
QtCore
.
Qt
.
CTRL
+
QtCore
.
Qt
.
Key_Q
)
QtCore
.
Qt
.
CTRL
+
QtCore
.
Qt
.
Key_Q
)
self
.
menuBar
().
addMenu
(
self
.
file_menu
)
self
.
help_menu
=
QMenu
(
'&Help'
,
self
)
self
.
help_menu
=
QtWidgets
.
QMenu
(
'&Help'
,
self
)
self
.
menuBar
().
addSeparator
()
self
.
menuBar
().
addMenu
(
self
.
help_menu
)
self
.
help_menu
.
addAction
(
'&About'
,
self
.
about
)
self
.
main_widget
=
QWidget
(
self
)
self
.
main_widget
=
QtWidgets
.
QWidget
(
self
)
l
=
QVBoxLayout
(
self
.
main_widget
)
l
=
QtWidgets
.
QVBoxLayout
(
self
.
main_widget
)
sc
=
MyStaticMplCanvas
(
self
.
main_widget
,
width
=
5
,
height
=
4
,
dpi
=
100
)
dc
=
MyDynamicMplCanvas
(
self
.
main_widget
,
width
=
5
,
height
=
4
,
dpi
=
100
)
l
.
addWidget
(
sc
)
...
...
@@ -96,25 +114,25 @@ class ApplicationWindow(QMainWindow):
self
.
fileQuit
()
def
about
(
self
):
QMessageBox
.
about
(
self
,
"About"
,
"""embedding_in_qt5.py example
Copyright 20
1
5
BoxControL
This program is a simple example of a Qt5 application embedding matplotlib
canvases.
It is base on example from matplolib documentation, and initially was
developed from Florent Rougon and Darren Dale.
http://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html
It may be used and modified with no restriction; raw copies as well as
modified versions may be distributed without limitation.
"""
)
if
__name__
==
'__main__'
:
app
=
QApplication
(
sys
.
argv
)
aw
=
ApplicationWindow
()
aw
.
setWindowTitle
(
"
PyQt5 Matplot Example"
)
aw
.
show
()
#
sys.exit(qApp.exec_())
a
pp
.
exec_
()
QtWidgets
.
QMessageBox
.
about
(
self
,
"About"
,
"""embedding_in_qt5.py example
Copyright 20
0
5
Florent Rougon, 2006 Darren Dale, 2015 Jens H Nielsen
This program is a simple example of a Qt5 application embedding matplotlib
canvases.
It may be used and modified with no restriction; raw copies as well as
modified versions may be distributed without limitation.
This is modified from the embedding in qt4 example to show the difference
between qt4 and qt5
"""
)
qApp
=
QtWidgets
.
QApplication
(
sys
.
argv
)
aw
=
ApplicationWindow
()
aw
.
setWindowTitle
(
"
%s"
%
progname
)
aw
.
show
()
sys
.
exit
(
qApp
.
exec_
())
#qA
pp.exec_()
myWin_Qt4Agg.py
View file @
2af2ac44
#!/usr/bin/env python
# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005 Florent Rougon
# 2006 Darren Dale
# ================= FILE HEADER ========================================
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.
# source: https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html
from
__future__
import
unicode_literals
import
sys
import
os
import
random
# myplotlib v3.0.1,
#
# @file myWin_Qt4Agg.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyWin_Qt4Agg class: Overlay of matplotlib FigureManager
# class. It allows a cleaner and more confortable
# usage of windows.
#
# @Class MyWin
#
# @Constructor
#
# fig: the MyFig object that need to be drawn
# show: a flag to show the window just after
# creation. (default: True)
# fignum: number of both the Window and the Figure.
# debug: flag for debugging, more verbatile.
# (kw)args: user defined arguments and keywords.
#
# @section Functions
#
# - _boundFigure_: bound a figure to the window (priv.)
#
# - _unboundFigure_: unbound a figure to the window (priv.)
#
# - set_figure: a clean way of setting a new figure
# to the window.
#
# - refresh: redraw the window
# - clean the figure
# - plot the figure
# - draw the canvas
#
# - drawFigure: draw a given figure on the window
# - set the figure of needed
# - refresh
#
# - close: close the window
#
# ======================================================================
#
# IMPORT ---------------------------------------------------------------
from
.
import
INFO
,
SEVR
,
WARN
,
DBUG
,
SPCE
from
.
import
rcParams
from
.
import
_G_WINDOWS
from
.
import
np
#~ from matplotlib.backends.backend_gtkagg import FigureManagerGTKAgg, FigureCanvasGTKAgg
# For the QtAgg backend
from
matplotlib.backends
import
qt4_compat
use_pyside
=
qt4_compat
.
QT_API
==
qt4_compat
.
QT_API_PYSIDE
if
use_pyside
:
from
PySide
import
QtGui
,
QtCore
else
:
from
PyQt4
import
QtGui
,
QtCore
from
numpy
import
arange
,
sin
,
pi
from
matplotlib.backends.backend_qt4agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
progname
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
progversion
=
"0.1"
class
MyMplCanvas
(
FigureCanvas
):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def
__init__
(
self
,
parent
=
None
,
width
=
5
,
height
=
4
,
dpi
=
100
):
fig
=
Figure
(
figsize
=
(
width
,
height
),
dpi
=
dpi
)
self
.
axes
=
fig
.
add_subplot
(
111
)
# We want the axes cleared every time plot() is called
self
.
axes
.
hold
(
False
)
self
.
compute_initial_figure
()
#
FigureCanvas
.
__init__
(
self
,
fig
)
from
matplotlib.backends.backend_qt4agg
import
FigureCanvasQTAgg
# Class MyWin Overwriting the disgusting Matplotlib.FigureManager class
class
MyWin_GTKAgg
(
FigureCanvasQTAgg
):
# CONSTRUCTOR ------------------------------------------------------
def
__init__
(
self
,
fig
,
show
=
True
,
*
args
,
**
kwargs
):
# set the dpi to 75 (correct value for screen)
if
(
fig
.
dpi
!=
75.
):
fig
.
dpi
=
75.
# Get the debug value
debug
=
kwargs
.
get
(
'debug'
,
False
)
# Get the user specified ID of the window or set it to 0
if
'fignum'
in
kwargs
.
keys
():
num
=
kwargs
[
'fignum'
]
fignumSpecifiedByUser
=
True
else
:
num
=
0
fignumSpecifiedByUser
=
False
# if ID already used
if
(
num
in
[(
window
.
num
)
for
window
in
_G_WINDOWS
]):
# if user specified fignum then close former window and create new one
if
(
fignumSpecifiedByUser
):
if
(
debug
):
print
(
DBUG
+
"The fignum you specified already exists, I'll close the former window"
)
# Close the window with the specified number
_G_WINDOWS
[
np
.
where
([(
window
.
num
==
num
)
for
window
in
_G_WINDOWS
])[
0
][
0
]].
close
()
else
:
# If user didn't specified a fignum
# increase ID until found a free one
while
(
num
in
[(
window
.
num
)
for
window
in
_G_WINDOWS
]):
num
=
num
+
1
# If debug print the ID of the window
if
(
debug
):
print
(
DBUG
+
"You choosed num = "
+
str
(
num
))
# before creating anything verify that the fig is not already
# bounded to another window
if
fig
.
boundedToWin
:
# if it is the case close the bounded window.
win
=
_G_WINDOWS
[
np
.
where
([(
window
.
num
==
fig
.
fignum
)
for
window
in
_G_WINDOWS
])[
0
][
0
]]
win
.
close
()
# Call FigureManagerGTK class
# (already wondering if this is not a mistake...)
if
(
debug
):
print
(
INFO
+
"Used GTKAgg backend."
)
# create the canvas
FigureCanvasQTAgg
.
__init__
(
self
,
fig
)
self
.
setParent
(
parent
)
FigureCanvas
.
setSizePolicy
(
self
,
FigureCanvas
QTAgg
.
setSizePolicy
(
self
,
QtGui
.
QSizePolicy
.
Expanding
,
QtGui
.
QSizePolicy
.
Expanding
)
FigureCanvas
.
updateGeometry
(
self
)
def
compute_initial_figure
(
self
):
pass
class
MyStaticMplCanvas
(
MyMplCanvas
):
"""Simple canvas with a sine plot."""
def
compute_initial_figure
(
self
):
t
=
arange
(
0.0
,
3.0
,
0.01
)
s
=
sin
(
2
*
pi
*
t
)
self
.
axes
.
plot
(
t
,
s
)
class
MyDynamicMplCanvas
(
MyMplCanvas
):
"""A canvas that updates itself every second with a new plot."""
def
__init__
(
self
,
*
args
,
**
kwargs
):
MyMplCanvas
.
__init__
(
self
,
*
args
,
**
kwargs
)
timer
=
QtCore
.
QTimer
(
self
)
timer
.
timeout
.
connect
(
self
.
update_figure
)
timer
.
start
(
1000
)
def
compute_initial_figure
(
self
):
self
.
axes
.
plot
([
0
,
1
,
2
,
3
],
[
1
,
2
,
0
,
4
],
'r'
)
def
update_figure
(
self
):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l
=
[
random
.
randint
(
0
,
10
)
for
i
in
range
(
4
)]
self
.
axes
.
plot
([
0
,
1
,
2
,
3
],
l
,
'r'
)
self
.
draw
()
class
ApplicationWindow
(
QtGui
.
QMainWindow
):
def
__init__
(
self
):
QtGui
.
QMainWindow
.
__init__
(
self
)
self
.
setAttribute
(
QtCore
.
Qt
.
WA_DeleteOnClose
)
self
.
setWindowTitle
(
"application main window"
)
self
.
file_menu
=
QtGui
.
QMenu
(
'&File'
,
self
)
self
.
file_menu
.
addAction
(
'&Quit'
,
self
.
fileQuit
,
QtCore
.
Qt
.
CTRL
+
QtCore
.
Qt
.
Key_Q
)
self
.
menuBar
().
addMenu
(
self
.
file_menu
)
self
.
help_menu
=
QtGui
.
QMenu
(
'&Help'
,
self
)
self
.
menuBar
().
addSeparator
()
self
.
menuBar
().
addMenu
(
self
.
help_menu
)
self
.
help_menu
.
addAction
(
'&About'
,
self
.
about
)
self
.
main_widget
=
QtGui
.
QWidget
(
self
)
l
=
QtGui
.
QVBoxLayout
(
self
.
main_widget
)
sc
=
MyStaticMplCanvas
(
self
.
main_widget
,
width
=
5
,
height
=
4
,
dpi
=
100
)
dc
=
MyDynamicMplCanvas
(
self
.
main_widget
,
width
=
5
,
height
=
4
,
dpi
=
100
)
l
.
addWidget
(
sc
)
l
.
addWidget
(
dc
)
self
.
main_widget
.
setFocus
()
self
.
setCentralWidget
(
self
.
main_widget
)
self
.
statusBar
().
showMessage
(
"All hail matplotlib!"
,
2000
)
def
fileQuit
(
self
):
self
.
close
()
def
closeEvent
(
self
,
ce
):
self
.
fileQuit
()
def
about
(
self
):
QtGui
.
QMessageBox
.
about
(
self
,
"About"
,
"""embedding_in_qt4.py example
Copyright 2005 Florent Rougon, 2006 Darren Dale
This program is a simple example of a Qt4 application embedding matplotlib
canvases.
It may be used and modified with no restriction; raw copies as well as
modified versions may be distributed without limitation."""
)
qApp
=
QtGui
.
QApplication
(
sys
.
argv
)
aw
=
ApplicationWindow
()
aw
.
setWindowTitle
(
"%s"
%
progname
)
aw
.
show
()
sys
.
exit
(
qApp
.
exec_
())
#qApp.exec_()
FigureCanvasQTAgg
.
updateGeometry
(
self
)
# bound the figure to the window
self
.
canvas
.
figure
.
boundedToWin
=
True
self
.
canvas
.
figure
.
fignum
=
num
# add the window in the global variable _G_WINDOWS
# this guarenty that you never loose a window
# (see myTool.py getWindow(num))
_G_WINDOWS
.
append
(
self
)
# if show is on, then show the window
if
show
:
# For GTKAgg and TKAgg ---------------------------------
self
.
refresh
()
self
.
show
()
# BOUND ------------------------------------------------------------
def
_boundFigure_
(
self
,
fig
):
fig
.
canvas
=
self
.
canvas
self
.
canvas
.
figure
=
fig
self
.
canvas
.
figure
.
boundedToWin
=
True
self
.
canvas
.
figure
.
fignum
=
self
.
num
# UNBOUND ----------------------------------------------------------
def
_unboundFigure_
(
self
):
self
.
canvas
.
figure
.
boundedToWin
=
False
self
.
canvas
.
figure
.
fignum
=
-
1
# SETTERS ----------------------------------------------------------
# SET FIGURE -------------------------------------------------------
def
set_figure
(
self
,
fig
):
# first unbound the former figure
self
.
_unboundFigure_
()
# if the new figure is already bounded close
# its former container.
if
fig
.
boundedToWin
:
win
=
_G_WINDOWS
[
np
.
where
([(
window
.
num
==
fig
.
fignum
)
for
window
in
_G_WINDOWS
])[
0
][
0
]]
win
.
close
()
# bound the new figure
self
.
_boundFigure_
(
fig
)
# REFRESH ----------------------------------------------------------
def
refresh
(
self
):
# in the case the figure got another canvas
# rebound the figure. This situation should not happend!!
if
self
.
canvas
!=
self
.
canvas
.
figure
.
canvas
:
print
(
WARN
+
"Something weird happend, the canvas of the figure have been changed"
)
self
.
set_figure
(
self
.
canvas
.
figure
)
# refresh
self
.
canvas
.
figure
.
plot
()
self
.
canvas
.
draw
()
return
(
True
)
# DRAW -------------------------------------------------------------
def
drawFigure
(
self
,
fig
):
# if the figure is not the current one
if
(
fig
.
fignum
!=
self
.
num
):
# cleanly set the new figure
self
.
set_figure
(
fig
)
# and refresh
self
.
refresh
()