How to migrate from guiqwt

This section describes the steps to migrate python code using guiqwt to plotpy.

Updating the imports

The following table gives the equivalence between guiqwt and plotpy classes.

For most of them, the change in the module path is the only difference (only the import statement have to be updated in your client code). For others, the third column of this table gives more details about the changes that may be required in your code.

Compatibility table

guiqwt v4

PlotPy v2

API changes

guiqwt.events

plotpy.events

guiqwt.interfaces

plotpy.interfaces

guiqwt.io

plotpy.io

guiqwt.io.eliminate_outliers

removed

guiqwt.annotations

plotpy.items

guiqwt.curve

plotpy.items

guiqwt.image

plotpy.items

guiqwt.label

plotpy.items

guiqwt.shapes

plotpy.items

guiqwt.histogram.HistogramItem

plotpy.items.HistogramItem

guiqwt.histogram.HistDataSource

plotpy.items.histogram.HistDataSource

guiqwt.histogram.hist_range_threshold

plotpy.lutrange.hist_range_threshold

guiqwt.histogram.lut_range_threshold

plotpy.lutrange.lut_range_threshold

guiqwt.histogram.ContrastAdjustment

plotpy.panels.contrastadjustment.ContrastAdjustment

guiqwt.image.get_items_in_rectangle

plotpy.items.get_items_in_rectangle

guiqwt.curve.PlotItemList

plotpy.panels.itemlist.PlotItemList

guiqwt.cross_section.XCrossSection

plotpy.panels.csection.cswidget.XCrossSection

guiqwt.cross_section.YCrossSection

plotpy.panels.csection.cswidget.YCrossSection

guiqwt.cross_section.ObliqueCrossSection

plotpy.panels.csection.cswidget.ObliqueCrossSection

guiqwt.plot.PlotManager

plotpy.plot.PlotManager

guiqwt.plot.CurveWindow

plotpy.plot.PlotWindow

See Generic PlotWidgets

guiqwt.plot.BaseImageWidget

plotpy.plot.BasePlotWidget

See Generic PlotWidgets

guiqwt.plot.CurveWidget

plotpy.plot.PlotWidget

See Generic PlotWidgets

guiqwt.plot.CurveWidgetMixin

*removed*

See Generic PlotWidgets

guiqwt.plot.CurveDialog

plotpy.plot.PlotDialog

See Generic PlotWidgets

guiqwt.curve.CurvePlot

plotpy.plot.baseplot.BasePlot

See Generic PlotWidgets

guiqwt.curve.CurvePlot.canvas2plotitem

removed

guiqwt.curve.CurvePlot.plotitem2canvas

removed

guiqwt.plot.SubplotWidget

plotpy.plot.SubplotWidget

guiqwt.pyplot

plotpy.pyplot

guiqwt.styles

plotpy.styles

guiqwt.tools

plotpy.tools

guiqwt.colormap

plotpy.mathutils.colormap

guiqwt.geometry

plotpy.mathutils.geometry

guiqwt.qthelpers.exec_image_save_dialog

plotpy.widgets.imagefile.exec_image_save_dialog

guiqwt.qthelpers.exec_image_open_dialog

plotpy.widgets.imagefile.exec_image_open_dialog

guiqwt.qthelpers.exec_images_open_dialog

plotpy.widgets.imagefile.exec_images_open_dialog

guiqwt.qthelpers.mimedata2url

removed

guiqwt.scaler

plotpy.mathutils.scaler

guiqwt.debug

removed

guiqwt.debug.buttons_to_str

plotpy.events.buttons_to_str

guiqwt.debug.evt_type_to_str

plotpy.events.evt_type_to_str

guiqwt.debug.print_event

removed

guiqwt.debug.qimage_format

removed

guiqwt.debug.qimage_to_str

removed

guiqwt.widgets.fit

plotpy.widgets.fit

guiqwt.widgets.rotatecrop

plotpy.widgets.rotatecrop

guiqwt.widgets.fliprotate

plotpy.widgets.fliprotate

guiqwt.widgets.rotatecrop

plotpy.widgets.rotatecrop

guiqwt.qtdesigner

plotpy.widgets.qtdesigner

Generic PlotWidgets

The Curve and Image plot widgets/dialogs/windows classes have been merged into generic classes capable of handling both plot items types.

As a consequence :

  • The CurvePlot and ImagePlot classes have been removed. If you are using them in your code, you can replace them by the BasePlot class which takes only one argument for configuration, named options (a BasePlotOptions instance). Choosing between curve and image plot is now done by setting the type attribute of the plot options (that may be set to 'curve' or 'image' for example). See also the Minor changes to the BasePlot class section.

  • The CurveWidget and ImageWidget classes have been merged into the new class PlotWidget. If you are using them in your code, you can replace them by the PlotWidget class, which takes only one argument for configuration, named options (a PlotOptions instance). Choosing between curve and image plot is now done by setting the type attribute of the plot options (that may be set to 'curve' or 'image' for example).

  • The CurveDialog and ImageDialog classes have been merged into the new class PlotDialog. If you are using them in your code, you may proceed as for the CurveWidget and ImageWidget classes.

  • The CurveWindow and ImageWindow classes have been merged into the new class PlotWindow. If you are using them in your code, you may proceed as for the CurveWidget and ImageWidget classes.

Note

Instead of setting the type plot option attribute to 'curve' or 'image', as stated above, you may consider using the 'auto' value or the 'manual' value.

See demo script tests/features/test_plot_types.py.

Minor changes to the BasePlot class

Some small changes of the BasePlot class related to the Generic PlotWidgets may require some minor adaptation of your code:

  • The BasePlot.del_all_items() method now has an except_grid keyword argument defaulting to True. This functionality was previously only present in child classes starting from CurvePlot, and has been merged into the parent class BasePlot. As a consequence, if you used the BasePlot class directly (without using CurvePlot or other child classes), you may want to pass except_grid=False to your BasePlot.del_all_items() calls.

  • Some arguments were added to the constructor of the BasePlot class (the arguments of the constructors of the old classes CurvePlot and ImagePlot have been merged): the new type of the plot (see Generic PlotWidgets), and the arguments of the ImagePlot constructor that the CurvePlot constructor missed : zlabel, zunit, yreverse, aspect_ratio, lock_aspect_ratio and force_colorbar_enabled. As a consequence, if you did not use keywords, but positional-only arguments when instantiating a CurvePlot or ImagePlot, you should adapt the new calls to the BasePlot constructor to meet the new arguments list.

Renamed update_curve and update_image methods

The update_image method of the classes BaseImageParam, QuadGridParam and their subclasses has been renamed to update_item.

The update_curve method of the classes CurveParam, ErrorBarParam and their subclasses has also been renamed to update_item.

This change allows to treat plot items parameters in a more generic way in client code.

Renamed PlotItems fields

The imageparam and curveparam fields of all plot item classes have been renamed to param.

This change allows to treat curve and image plot items in a more generic way in client code.

New features

The following subsections present new features that may help you to simplify you code using plotpy.

New method for thresholding image item LUTs

The method plotpy.items.BaseImageItem.set_lut_threshold() has been added. It allows to set the percentage of outliers to be clipped from the image histogram values.

This method is available for all image items:

New annotation tools registration methods

Some new methods were added to class PlotManager:

You may use those methods to simplify you code if you were previously registering annotation tools one by one.

See demo script tests/items/test_annotations.py.

New contour features

plotpy integrates now a contour detection algorithm, so that plotpy based applications depending on matplotlib only for this function can drop this additional dependency.

See demo script tests/items/test_contour.py.

MaskedXYImages

You can now use the MaskedXYImageItem to apply masks to XYImageItems (only ImageItems where previously maskable with the class MaskedImageItem.

You can use the convenience methods PlotBuilder.maskedxyimage() to help you build such items.

See demo script tests/items/test_image_masked_xy.py.

New options added to plot builder

The PlotItemBuilder factory class has been renamed to PlotBuilder, because it provides not only methods for creating plot items, but also methods for creating ready-to-use plots.

New methods for creating ready-to-use plots have been added to the class:

The method PlotBuilder.contours() has been added, in order to create contour curves. It returns a list of plotpy.items.ContourItem objects.

See demo script tests/items/test_contour.py.

The new keyword parameter alpha_function has been added to the methods PlotBuilder.image(), PlotBuilder.xyimage(), PlotBuilder.maskedimage(), PlotBuilder.maskedxyimage(), PlotBuilder.trimage(), PlotBuilder.rgbimage(), and PlotBuilder.quadgrid(). It allows to specify a function to compute the alpha channel of the image from the data values. The supported functions are:

Warning

The alpha_mask parameter has been removed from the methods PlotBuilder.image(), PlotBuilder.xyimage(), PlotBuilder.maskedimage(), PlotBuilder.maskedxyimage(), PlotBuilder.trimage(), PlotBuilder.rgbimage(), and PlotBuilder.quadgrid(). If you were using it, you should replace it by the new alpha_function parameter.

The new keyword parameter lut_range has been added to the methods PlotBuilder.image(), PlotBuilder.xyimage(), PlotBuilder.maskedimage(), PlotBuilder.maskedxyimage(), and PlotBuilder.trimage(), so you can now avoid to make calls to set_lut_range after the PlotItem is built.

See demo script tests/features/test_builder.py.

The method PlotBuilder.image() now accepts optional x and y keyword arguments, to automatically create a plotpy.items.XYImageItem instead of a simple plotpy.items.ImageItem if needed.

See demo script tests/features/test_builder.py.

The method PlotBuilder.curve() now accepts optional dx, dy, errorbarwidth, errorbarcap, errorbarmode, errorbaralpha keyword arguments, to automatically create a plotpy.items.ErrorBarCurveItem instead of a simple plotpy.items.CurveItem if needed.

See demo script tests/features/test_builder.py.

Transformation (translation, rotate, resize) of ImageItem

Most ImageItem can now be selected, translated, rotated and resized.

Auto-scaling and shapes

Auto-scaling takes now into account visible shapes (subclasses of PolygonShape).

See demo script tests/features/test_autoscale_shapes.py.