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.
guiqwt v4 |
PlotPy v2 |
API changes |
|
|
|
|
|
|
|
|
|
|
removed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
removed |
|
|
removed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
removed |
|
|
|
|
|
removed |
|
|
|
|
|
|
|
|
removed |
|
|
removed |
|
|
removed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
CurvePlotandImagePlotclasses have been removed. If you are using them in your code, you can replace them by theBasePlotclass which takes only one argument for configuration, named options (aBasePlotOptionsinstance). 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
CurveWidgetandImageWidgetclasses have been merged into the new classPlotWidget. If you are using them in your code, you can replace them by thePlotWidgetclass, which takes only one argument for configuration, named options (aPlotOptionsinstance). 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 theCurveWidgetandImageWidgetclasses.The
CurveWindowandImageWindowclasses have been merged into the new classPlotWindow. If you are using them in your code, you may proceed as for theCurveWidgetandImageWidgetclasses.
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 anexcept_gridkeyword argument defaulting toTrue. This functionality was previously only present in child classes starting fromCurvePlot, and has been merged into the parent classBasePlot. As a consequence, if you used theBasePlotclass directly (without usingCurvePlotor other child classes), you may want to passexcept_grid=Falseto yourBasePlot.del_all_items()calls.Some arguments were added to the constructor of the
BasePlotclass (the arguments of the constructors of the old classesCurvePlotandImagePlothave been merged): the new type of the plot (see Generic PlotWidgets), and the arguments of theImagePlotconstructor that theCurvePlotconstructor missed :zlabel,zunit,yreverse,aspect_ratio,lock_aspect_ratioandforce_colorbar_enabled. As a consequence, if you did not use keywords, but positional-only arguments when instantiating aCurvePlotorImagePlot, you should adapt the new calls to theBasePlotconstructor 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:
PlotManager.register_curve_annotation_tools(): register all curve related annotation tools,PlotManager.register_image_annotation_tools(): register all image related annotation tools,PlotManager.register_all_annotation_tools(): register all annotation tools.
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 contour detection plot items, based on the contour detection algorithm provided by the scikit-image library.
As a consequence, the applications that previously depended on matplotlib only for contour detection can now drop this 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:
plotpy.constants.LUTAlpha.NONE(default)
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.