guiqwt.plot

The plot module provides the following features:
  • guiqwt.plot.PlotManager: the plot manager is an object to link plots, panels and tools together for designing highly versatile graphical user interfaces
  • guiqwt.plot.CurveWidget: a ready-to-use widget for curve displaying with an integrated and preconfigured plot manager providing the item list panel and curve-related tools
  • guiqwt.plot.CurveDialog: a ready-to-use dialog box for curve displaying with an integrated and preconfigured plot manager providing the item list panel and curve-related tools
  • guiqwt.plot.ImageWidget: a ready-to-use widget for curve and image displaying with an integrated and preconfigured plot manager providing the item list panel, the contrast adjustment panel, the cross section panels (along X and Y axes) and image-related tools (e.g. colormap selection tool)
  • guiqwt.plot.ImageDialog: a ready-to-use dialog box for curve and image displaying with an integrated and preconfigured plot manager providing the item list panel, the contrast adjustment panel, the cross section panels (along X and Y axes) and image-related tools (e.g. colormap selection tool)

See also

Module guiqwt.curve
Module providing curve-related plot items and plotting widgets
Module guiqwt.image
Module providing image-related plot items and plotting widgets
Module guiqwt.tools
Module providing the plot tools
Module guiqwt.panels
Module providing the plot panels IDs
Module guiqwt.baseplot
Module providing the guiqwt plotting widget base class

Class diagrams

Curve-related widgets with integrated plot manager:

../_images/curve_widgets.png

Image-related widgets with integrated plot manager:

../_images/image_widgets.png

Building your own plot manager:

../_images/my_plot_manager.png

Examples

Simple example without the plot manager:


from guidata.qt.QtGui import QWidget, QVBoxLayout, QHBoxLayout, QPushButton

#---Import plot widget base class
from guiqwt.plot import CurveWidget
from guiqwt.builder import make
from guidata.configtools import get_icon
#---

class FilterTestWidget(QWidget):
    """
    Filter testing widget
    parent: parent widget (QWidget)
    x, y: NumPy arrays
    func: function object (the signal filter to be tested)
    """
    def __init__(self, parent, x, y, func):
        QWidget.__init__(self, parent)
        self.setMinimumSize(320, 200)
        self.x = x
        self.y = y
        self.func = func
        #---guiqwt curve item attribute:
        self.curve_item = None
        #---
        
    def setup_widget(self, title):
        #---Create the plot widget:
        curvewidget = CurveWidget(self)
        curvewidget.register_all_curve_tools()
        self.curve_item = make.curve([], [], color='b')
        curvewidget.plot.add_item(self.curve_item)
        curvewidget.plot.set_antialiasing(True)
        #---
        
        button = QPushButton("Test filter: %s" % title)
        button.clicked.connect(self.process_data)
        vlayout = QVBoxLayout()
        vlayout.addWidget(curvewidget)
        vlayout.addWidget(button)
        self.setLayout(vlayout)
        
        self.update_curve()
        
    def process_data(self):
        self.y = self.func(self.y)
        self.update_curve()
        
    def update_curve(self):
        #---Update curve
        self.curve_item.set_data(self.x, self.y)
        self.curve_item.plot().replot()
        #---
    
    
class TestWindow(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.setWindowTitle("Signal filtering (guiqwt)")
        self.setWindowIcon(get_icon('guiqwt.svg'))
        hlayout = QHBoxLayout()
        self.setLayout(hlayout)
        
    def add_plot(self, x, y, func, title):
        widget = FilterTestWidget(self, x, y, func)
        widget.setup_widget(title)
        self.layout().addWidget(widget)
        

def test():
    """Testing this simple Qt/guiqwt example"""
    from guidata.qt.QtGui import QApplication
    import numpy as np
    import scipy.signal as sps, scipy.ndimage as spi
    
    app = QApplication([])
    win = TestWindow()
    
    x = np.linspace(-10, 10, 500)
    y = np.random.rand(len(x))+5*np.sin(2*x**2)/x
    win.add_plot(x, y, lambda x: spi.gaussian_filter1d(x, 1.), "Gaussian")
    win.add_plot(x, y, sps.wiener, "Wiener")
    
    win.show()
    app.exec_()
        
        
if __name__ == '__main__':
    test()
    

Simple example with the plot manager: even if this simple example does not justify the use of the plot manager (this is an unnecessary complication here), it shows how to use it. In more complex applications, using the plot manager allows to design highly versatile graphical user interfaces.


from guidata.qt.QtGui import (QWidget, QVBoxLayout, QHBoxLayout, QPushButton,
                              QMainWindow)

#---Import plot widget base class
from guiqwt.curve import CurvePlot
from guiqwt.plot import PlotManager
from guiqwt.builder import make
from guidata.configtools import get_icon
#---

class FilterTestWidget(QWidget):
    """
    Filter testing widget
    parent: parent widget (QWidget)
    x, y: NumPy arrays
    func: function object (the signal filter to be tested)
    """
    def __init__(self, parent, x, y, func):
        QWidget.__init__(self, parent)
        self.setMinimumSize(320, 200)
        self.x = x
        self.y = y
        self.func = func
        #---guiqwt related attributes:
        self.plot = None
        self.curve_item = None
        #---
        
    def setup_widget(self, title):
        #---Create the plot widget:
        self.plot = CurvePlot(self)
        self.curve_item = make.curve([], [], color='b')
        self.plot.add_item(self.curve_item)
        self.plot.set_antialiasing(True)
        #---
        
        button = QPushButton("Test filter: %s" % title)
        button.clicked.connect(self.process_data)
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.plot)
        vlayout.addWidget(button)
        self.setLayout(vlayout)
        
        self.update_curve()
        
    def process_data(self):
        self.y = self.func(self.y)
        self.update_curve()
        
    def update_curve(self):
        #---Update curve
        self.curve_item.set_data(self.x, self.y)
        self.plot.replot()
        #---
    
    
class TestWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("Signal filtering 2 (guiqwt)")
        self.setWindowIcon(get_icon('guiqwt.svg'))
        
        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        #---guiqwt plot manager
        self.manager = PlotManager(self)
        #---
        
    def add_plot(self, x, y, func, title):
        widget = FilterTestWidget(self, x, y, func)
        widget.setup_widget(title)
        self.centralWidget().layout().addWidget(widget)
        #---Register plot to manager
        self.manager.add_plot(widget.plot)
        #---
        
    def setup_window(self):
        #---Add toolbar and register manager tools
        toolbar = self.addToolBar("tools")
        self.manager.add_toolbar(toolbar, id(toolbar))
        self.manager.register_all_curve_tools()
        #---
        

def test():
    """Testing this simple Qt/guiqwt example"""
    from guidata.qt.QtGui import QApplication
    import numpy as np
    import scipy.signal as sps, scipy.ndimage as spi
    
    app = QApplication([])
    win = TestWindow()
    
    x = np.linspace(-10, 10, 500)
    y = np.random.rand(len(x))+5*np.sin(2*x**2)/x
    win.add_plot(x, y, lambda x: spi.gaussian_filter1d(x, 1.), "Gaussian")
    win.add_plot(x, y, sps.wiener, "Wiener")
    #---Setup window
    win.setup_window()
    #---
    
    win.show()
    app.exec_()
        
        
if __name__ == '__main__':
    test()
    

Reference

class guiqwt.plot.PlotManager(main)[source]

Construct a PlotManager object, a ‘controller’ that organizes relations between plots (i.e. guiqwt.curve.CurvePlot or guiqwt.image.ImagePlot objects), panels, tools (see guiqwt.tools) and toolbars

add_plot(plot, plot_id=<class 'guiqwt.plot.DefaultPlotID'>)[source]
Register a plot to the plot manager:
  • plot: guiqwt.curve.CurvePlot or guiqwt.image.ImagePlot object
  • plot_id (default id is the plot object’s id: id(plot)): unique ID identifying the plot (any Python object), this ID will be asked by the manager to access this plot later.
Plot manager’s registration sequence is the following:
  1. add plots
  2. add panels
  3. add tools
set_default_plot(plot)[source]

Set default plot

The default plot is the plot on which tools and panels will act.

get_default_plot()[source]

Return default plot

The default plot is the plot on which tools and panels will act.

add_panel(panel)[source]

Register a panel to the plot manager

Plot manager’s registration sequence is the following:
  1. add plots
  2. add panels
  3. add tools
configure_panels()[source]

Call all the registred panels ‘configure_panel’ methods to finalize the object construction (this allows to use tools registered to the same plot manager as the panel itself with breaking the registration sequence: “add plots, then panels, then tools”)

add_toolbar(toolbar, toolbar_id='default')[source]
Add toolbar to the plot manager
toolbar: a QToolBar object toolbar_id: toolbar’s id (default id is string “default”)
set_default_toolbar(toolbar)[source]

Set default toolbar

get_default_toolbar()[source]

Return default toolbar

add_tool(ToolKlass, *args, **kwargs)[source]
Register a tool to the manager
  • ToolKlass: tool’s class (guiqwt builtin tools are defined in module guiqwt.tools)
  • args: arguments sent to the tool’s class
  • kwargs: keyword arguments sent to the tool’s class
Plot manager’s registration sequence is the following:
  1. add plots
  2. add panels
  3. add tools
get_tool(ToolKlass)[source]

Return tool instance from its class

add_separator_tool(toolbar_id=None)[source]

Register a separator tool to the plot manager: the separator tool is just a tool which insert a separator in the plot context menu

set_default_tool(tool)[source]

Set default tool

get_default_tool()[source]

Get default tool

activate_default_tool()[source]

Activate default tool

get_active_tool()[source]

Return active tool

set_active_tool(tool=None)[source]

Set active tool (if tool argument is None, the active tool will be the default tool)

get_plot(plot_id=<class 'guiqwt.plot.DefaultPlotID'>)[source]

Return plot associated to plot_id (if method is called without specifying the plot_id parameter, return the default plot)

get_plots()[source]

Return all registered plots

get_active_plot()[source]

Return the active plot

The active plot is the plot whose canvas has the focus otherwise it’s the “default” plot

get_main()[source]

Return the main (parent) widget

Note that for py:class:guiqwt.plot.CurveWidget or guiqwt.plot.ImageWidget objects, this method will return the widget itself because the plot manager is integrated to it.

get_panel(panel_id)[source]

Return panel from its ID Panel IDs are listed in module guiqwt.panels

get_itemlist_panel()[source]

Convenience function to get the item list panel

Return None if the item list panel has not been added to this manager

get_contrast_panel()[source]

Convenience function to get the contrast adjustment panel

Return None if the contrast adjustment panel has not been added to this manager

set_contrast_range(zmin, zmax)[source]

Convenience function to set the contrast adjustment panel range

This is strictly equivalent to the following:

# Here, *widget* is for example a CurveWidget instance
# (the same apply for CurvePlot, ImageWidget, ImagePlot or any 
#  class deriving from PlotManager)
widget.get_contrast_panel().set_range(zmin, zmax)
get_xcs_panel()[source]

Convenience function to get the X-axis cross section panel

Return None if the X-axis cross section panel has not been added to this manager

get_ycs_panel()[source]

Convenience function to get the Y-axis cross section panel

Return None if the Y-axis cross section panel has not been added to this manager

update_cross_sections()[source]

Convenience function to update the cross section panels at once

This is strictly equivalent to the following:

# Here, *widget* is for example a CurveWidget instance
# (the same apply for CurvePlot, ImageWidget, ImagePlot or any 
#  class deriving from PlotManager)
widget.get_xcs_panel().update_plot()
widget.get_ycs_panel().update_plot()
get_toolbar(toolbar_id='default')[source]
Return toolbar from its ID
toolbar_id: toolbar’s id (default id is string “default”)
get_context_menu(plot=None)[source]

Return widget context menu – built using active tools

update_tools_status(plot=None)[source]

Update tools for current plot

create_action(title, triggered=None, toggled=None, shortcut=None, icon=None, tip=None, checkable=None, context=1, enabled=None)[source]

Create a new QAction

register_standard_tools()[source]

Registering basic tools for standard plot dialog –> top of the context-menu

register_curve_tools()[source]

Register only curve-related tools

register_image_tools()[source]

Register only image-related tools

register_other_tools()[source]

Register other common tools

register_all_curve_tools()[source]

Register standard, curve-related and other tools

register_all_image_tools()[source]

Register standard, image-related and other tools

class guiqwt.plot.CurveWidget(parent=None, title=None, xlabel=None, ylabel=None, xunit=None, yunit=None, section='plot', show_itemlist=False, gridparam=None, panels=None)[source]

Construct a CurveWidget object: plotting widget with integrated plot manager

  • parent: parent widget
  • title: plot title
  • xlabel: (bottom axis title, top axis title) or bottom axis title only
  • ylabel: (left axis title, right axis title) or left axis title only
  • xunit: (bottom axis unit, top axis unit) or bottom axis unit only
  • yunit: (left axis unit, right axis unit) or left axis unit only
  • panels (optional): additionnal panels (list, tuple)
class guiqwt.plot.CurveDialog(wintitle='guiqwt plot', icon='guiqwt.svg', edit=False, toolbar=False, options=None, parent=None, panels=None)[source]

Construct a CurveDialog object: plotting dialog box with integrated plot manager

  • wintitle: window title
  • icon: window icon
  • edit: editable state
  • toolbar: show/hide toolbar
  • options: options sent to the guiqwt.curve.CurvePlot object (dictionary)
  • parent: parent widget
  • panels (optional): additionnal panels (list, tuple)
install_button_layout()[source]

Install standard buttons (OK, Cancel) in dialog button box layout (guiqwt.plot.CurveDialog.button_layout)

This method may be overriden to customize the button box

class guiqwt.plot.ImageWidget(parent=None, title='', xlabel=('', ''), ylabel=('', ''), zlabel=None, xunit=('', ''), yunit=('', ''), zunit=None, yreverse=True, colormap='jet', aspect_ratio=1.0, lock_aspect_ratio=True, show_contrast=False, show_itemlist=False, show_xsection=False, show_ysection=False, xsection_pos='top', ysection_pos='right', gridparam=None, panels=None)[source]

Construct a ImageWidget object: plotting widget with integrated plot manager

  • parent: parent widget
  • title: plot title (string)
  • xlabel, ylabel, zlabel: resp. bottom, left and right axis titles (strings)
  • xunit, yunit, zunit: resp. bottom, left and right axis units (strings)
  • yreverse: reversing Y-axis (bool)
  • aspect_ratio: height to width ratio (float)
  • lock_aspect_ratio: locking aspect ratio (bool)
  • show_contrast: showing contrast adjustment tool (bool)
  • show_xsection: showing x-axis cross section plot (bool)
  • show_ysection: showing y-axis cross section plot (bool)
  • xsection_pos: x-axis cross section plot position (string: “top”, “bottom”)
  • ysection_pos: y-axis cross section plot position (string: “left”, “right”)
  • panels (optional): additionnal panels (list, tuple)
class guiqwt.plot.ImageDialog(wintitle='guiqwt plot', icon='guiqwt.svg', edit=False, toolbar=False, options=None, parent=None, panels=None)[source]

Construct a ImageDialog object: plotting dialog box with integrated plot manager

  • wintitle: window title
  • icon: window icon
  • edit: editable state
  • toolbar: show/hide toolbar
  • options: options sent to the guiqwt.image.ImagePlot object (dictionary)
  • parent: parent widget
  • panels (optional): additionnal panels (list, tuple)