Skip to content

Commit 6684fbc

Browse files
committed
Update plot_curve.py
1 parent d3e93d9 commit 6684fbc

File tree

1 file changed

+64
-16
lines changed

1 file changed

+64
-16
lines changed

qwt/plot_curve.py

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -813,51 +813,99 @@ def legendIcon(self, index, size):
813813
self.__data.symbol.drawSymbol(painter, r)
814814
return graphic
815815

816-
def setData(self, *args):
817-
"""Compatibility with Qwt5"""
818-
if len(args) == 1:
816+
def setData(self, *args, **kwargs):
817+
"""
818+
Initialize data with a series data object or an array of points.
819+
820+
.. py:method:: setData(data):
821+
822+
:param data: Series data (e.g. `QwtPointArrayData` instance)
823+
:type data: qwt.plot_series.QwtSeriesData
824+
825+
.. py:method:: setData(xData, yData, [size=None], [finite=True]):
826+
827+
Initialize data with `x` and `y` arrays.
828+
829+
This signature was removed in Qwt6 and is temporarily maintained here to ensure compatibility with Qwt5.
830+
831+
Same as `setSamples(x, y, [size=None], [finite=True])`
832+
833+
:param x: List/array of x values
834+
:param y: List/array of y values
835+
:param size: size of xData and yData
836+
:type size: int or None
837+
:param bool finite: if True, keep only finite array elements (remove all infinity and not a number values), otherwise do not filter array elements
838+
839+
.. seealso::
840+
841+
:py:meth:`setSamples()`
842+
"""
843+
if len(args) == 1 and not kwargs:
819844
super(QwtPlotCurve, self).setData(*args)
820-
elif len(args) == 2:
821-
self.setSamples(*args)
845+
elif len(args) in (2, 3, 4):
846+
self.setSamples(*args, **kwargs)
822847
else:
823-
raise TypeError("%s().setData() takes 1 or 2 argument(s) (%s given)"\
848+
raise TypeError("%s().setData() takes 1, 2, 3 or 4 argument(s) (%s given)"\
824849
% (self.__class__.__name__, len(args)))
825850

826-
def setSamples(self, *args):
851+
def setSamples(self, *args, **kwargs):
827852
"""
828853
Initialize data with an array of points.
829854
855+
.. py:method:: setSamples(data):
856+
857+
:param data: Series data (e.g. `QwtPointArrayData` instance)
858+
:type data: qwt.plot_series.QwtSeriesData
859+
860+
830861
.. py:method:: setSamples(samples):
831862
832863
Same as `setData(QwtPointArrayData(samples))`
833864
834865
:param samples: List/array of points
835866
836-
.. py:method:: setSamples(xData, yData, [size=None]):
867+
.. py:method:: setSamples(xData, yData, [size=None], [finite=True]):
837868
838869
Same as `setData(QwtPointArrayData(xData, yData, [size=None]))`
839870
840871
:param xData: List/array of x values
841872
:param yData: List/array of y values
842873
:param size: size of xData and yData
843874
:type size: int or None
875+
:param bool finite: if True, keep only finite array elements (remove all infinity and not a number values), otherwise do not filter array elements
844876
845877
.. seealso::
846878
847-
:py:class:`qwt.plot_series.QwtPointArrayData`,
879+
:py:class:`qwt.plot_series.QwtPointArrayData`
848880
"""
849-
if len(args) == 1:
881+
if len(args) == 1 and not kwargs:
850882
samples, = args
851883
if isinstance(samples, QwtSeriesData):
852884
self.setData(samples)
853885
else:
854886
self.setData(QwtPointArrayData(samples))
855-
elif len(args) == 3:
856-
xData, yData, size = args
857-
self.setData(QwtPointArrayData(xData, yData, size))
858-
elif len(args) == 2:
859-
xData, yData = args
860-
self.setData(QwtPointArrayData(xData, yData))
887+
elif len(args) >= 2:
888+
xData, yData = args[:2]
889+
try:
890+
size = kwargs.pop('size')
891+
except KeyError:
892+
size = None
893+
try:
894+
finite = kwargs.pop('finite')
895+
except KeyError:
896+
finite = None
897+
if kwargs:
898+
raise TypeError("%s().setSamples(): unknown %s keyword "\
899+
"argument(s)"\
900+
% (self.__class__.__name__,
901+
", ".join(list(kwargs.keys()))))
902+
for arg in args[2:]:
903+
if isinstance(arg, bool):
904+
finite = arg
905+
elif isinstance(arg, int):
906+
size = arg
907+
self.setData(QwtPointArrayData(xData, yData,
908+
size=size, finite=finite))
861909
else:
862910
raise TypeError("%s().setSamples() takes 1, 2 or 3 argument(s) "\
863911
"(%s given)" % (self.__class__.__name__, len(args)))

0 commit comments

Comments
 (0)