@@ -812,12 +812,42 @@ def _simplifyLine(fighandle, axhandle, linehandle, target_resolution):
812
812
_removeData (linehandle , id_remove )
813
813
814
814
815
- removeData (linehandle , id_remove )
815
+ def _simplifyStairs (fighandle , axhandle , linehandle ):
816
+ # TODO: it looks like matlab changes the data to be plotted when using `stairs` command, whereas matplotlib stores the same data but displays it as a step.
816
817
818
+ xData = linehandle .get_xdata ()
819
+ yData = linehandle .get_ydata ()
820
+ data = np .stack ([xData , yData ], 1 )
821
+ if _isempty (xData ) or _isempty (yData ):
822
+ return
823
+
824
+ xNoDiff = np .concatenate ([np .array ([False ]).reshape ((- 1 ,) ), _diff (xData ) == 0 ])
825
+ yNoDiff = np .concatenate ([np .array ([False ]).reshape ((- 1 ,) ), _diff (yData ) == 0 ])
817
826
818
- def simplifyStairs (fighandle , axhandle , linehandle ):
819
- # TODO: implement this
820
- raise NotImplementedError
827
+ xNoDiff [- 1 ] = False
828
+ yNoDiff [- 1 ] = False
829
+
830
+ xIsMonotone = np .concatenate (
831
+ [
832
+ np .array ([True ]).reshape ((- 1 ,) ),
833
+ _diff (np .sign (_diff (xData ))) == 0 ,
834
+ np .array ([True ]).reshape ((- 1 ,) )
835
+ ]
836
+ )
837
+ yIsMonotone = np .concatenate (
838
+ [
839
+ np .array ([True ]).reshape ((- 1 ,) ),
840
+ _diff (np .sign (_diff (yData ))) == 0 ,
841
+ np .array ([True ]).reshape ((- 1 ,) )
842
+ ]
843
+ )
844
+ xRemove = np .logical_and (xNoDiff , yIsMonotone )
845
+ yRemove = np .logical_and (yNoDiff , xIsMonotone )
846
+
847
+ id_remove = np .argwhere (xRemove or yRemove )
848
+ new_data = _removeData (data , id_remove )
849
+ linehandle .set_xdata (new_data [:, 0 ])
850
+ linehandle .set_ydata (new_data [:, 1 ])
821
851
822
852
823
853
def _pixelate (x , y , xToPix , yToPix ):
0 commit comments