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
CurvePlot
andImagePlot
classes have been removed. If you are using them in your code, you can replace them by theBasePlot
class which takes only one argument for configuration, named options (aBasePlotOptions
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
andImageWidget
classes have been merged into the new classPlotWidget
. If you are using them in your code, you can replace them by thePlotWidget
class, which takes only one argument for configuration, named options (aPlotOptions
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 theCurveWidget
andImageWidget
classes.The
CurveWindow
andImageWindow
classes have been merged into the new classPlotWindow
. If you are using them in your code, you may proceed as for theCurveWidget
andImageWidget
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 anexcept_grid
keyword 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 theBasePlot
class directly (without usingCurvePlot
or other child classes), you may want to passexcept_grid=False
to yourBasePlot.del_all_items()
calls.Some arguments were added to the constructor of the
BasePlot
class (the arguments of the constructors of the old classesCurvePlot
andImagePlot
have been merged): the new type of the plot (see Generic PlotWidgets), and the arguments of theImagePlot
constructor that theCurvePlot
constructor missed :zlabel
,zunit
,yreverse
,aspect_ratio
,lock_aspect_ratio
andforce_colorbar_enabled
. As a consequence, if you did not use keywords, but positional-only arguments when instantiating aCurvePlot
orImagePlot
, you should adapt the new calls to theBasePlot
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
:
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 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:
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.