Merge pull request #84 from sanguinariojoe/master

Matplotlib navigation toolbar support
This commit is contained in:
Yorik van Havre 2016-01-28 13:06:38 -02:00
commit 5ec2ea0e6c

View File

@ -33,7 +33,7 @@ try:
matplotlib.rcParams['backend.qt4']='PySide'
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
if V(matplotlib.__version__) < V("1.5.0"):
if V(matplotlib.__version__) < V("1.4.0"):
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
else:
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
@ -337,6 +337,38 @@ def save(path, figsize=None, dpi=None):
plt.update()
def addNavigationToolbar():
"""Add the matplotlib QT navigation toolbar to the plot.
"""
plt = getPlot()
if not plt:
return
# Check that the navigation toolbar has not been already created
if plt.mpl_toolbar is not None:
return
# Create the navigation toolbar and add it
plt.mpl_toolbar = NavigationToolbar(plt.canvas, plt)
vbox = plt.layout()
vbox.addWidget(plt.mpl_toolbar)
def delNavigationToolbar():
"""Remove the matplotlib QT navigation toolbar from the plot.
"""
plt = getPlot()
if not plt:
return
# Check that the navigation toolbar already exist
if plt.mpl_toolbar is None:
return
# Remove the widget from the layout
vbox = plt.layout()
vbox.removeWidget(plt.mpl_toolbar)
# Destroy the navigation toolbar
plt.mpl_toolbar.deleteLater()
plt.mpl_toolbar = None
class Line():
def __init__(self, axes, x, y, name):
"""Construct a new plot serie.
@ -397,9 +429,12 @@ class Plot(PySide.QtGui.QWidget):
self.axes.spines['top'].set_color('none')
self.axes.yaxis.set_ticks_position('left')
self.axes.spines['right'].set_color('none')
# Add the navigation toolbar by default
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
# Setup layout
vbox = PySide.QtGui.QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
self.setLayout(vbox)
# Active series
self.series = []