1
1
import numpy as np
2
+ import matplotlib
2
3
from matplotlib import pyplot as plt
3
4
4
5
@@ -28,8 +29,19 @@ def cleanfigure(fighandle=None, axhandle=None, target_resolution=600, scalePreci
28
29
elif (fighandle is not None ) and (axhandle is None ):
29
30
axhandle = fighandle .axes [0 ]
30
31
32
+ # Note: ax.scatter and ax.plot create Line2D objects in a property ax.lines
33
+ # ax.bar creates BarContainer objects in a property ax.bar
34
+
31
35
for linehandle in axhandle .lines :
32
- cleanline (fighandle , axhandle , linehandle , target_resolution , scalePrecision )
36
+ if type (linehandle ) == matplotlib .lines .Line2D :
37
+ cleanline (fighandle , axhandle , linehandle , target_resolution , scalePrecision )
38
+ else :
39
+ raise NotImplementedError
40
+
41
+ for container in axhandle .containers :
42
+ if type (container ) == matplotlib .container .BarContainer :
43
+ pass
44
+
33
45
34
46
35
47
def cleanline (fighandle , axhandle , linehandle , target_resolution , scalePrecision ):
@@ -250,10 +262,12 @@ def elements(array):
250
262
"""
251
263
return array .ndim and array .size
252
264
265
+
253
266
def isempty (array ):
254
267
"""proxy for matlab / octave isempty function"""
255
268
return elements (array ) == 0
256
269
270
+
257
271
def pruneOutsideBox (fighandle , axhandle , linehandle ):
258
272
"""Some sections of the line may sit outside of the visible box. Cut those off.
259
273
@@ -300,6 +314,9 @@ def pruneOutsideBox(fighandle, axhandle, linehandle):
300
314
shouldPlot , np .concatenate ([segvis , np .array ([False ]).reshape ((- 1 ,))])
301
315
)
302
316
317
+ id_replace = np .array ([[]])
318
+ id_remove = np .array ([[]])
319
+
303
320
if not np .all (shouldPlot ):
304
321
id_remove = np .argwhere (np .logical_not (shouldPlot ))
305
322
@@ -593,9 +610,8 @@ def simplifyLine(fighandle, axhandle, linehandle, target_resolution):
593
610
if hasMarkers and not hasLines :
594
611
# Pixelate data at the zoom multiplier
595
612
# TODO implement this
596
- # mask = pixelate(xData, yData, xToPix, yToPix);
597
- # id_remove = find(mask==0);
598
- raise NotImplementedError
613
+ mask = pixelate (xData , yData , xToPix , yToPix )
614
+ id_remove = np .argwhere (mask * 1 == 0 )
599
615
elif hasLines and not hasMarkers :
600
616
# Get the width of a pixel
601
617
xPixelWidth = 1 / xToPix
@@ -645,6 +661,47 @@ def simplifyLine(fighandle, axhandle, linehandle, target_resolution):
645
661
linehandle .set_ydata (data [:, 1 ])
646
662
647
663
664
+
665
+
666
+ def pixelate (x , y , xToPix , yToPix ):
667
+ """Rough reduction of data points at a multiple of the target resolution.
668
+ The resolution is lost only beyond the multiplier magnification.
669
+
670
+ Parameters
671
+ ----------
672
+ x : [type]
673
+ [description]
674
+ y : [type]
675
+ [description]
676
+ xToPix : [type]
677
+ [description]
678
+ yToPix : [type]
679
+ [description]
680
+
681
+ Returns
682
+ -------
683
+ np.ndarray
684
+ boolean mask
685
+ """
686
+ # TODO: implement this
687
+ mult = 2
688
+ dataPixel = np .round (np .stack ([x * xToPix * mult , y * yToPix * mult ], axis = 1 ))
689
+ id_orig = np .argsort (dataPixel [:, 0 ])
690
+ dataPixelSorted = dataPixel [id_orig , :]
691
+
692
+ m = np .logical_or (np .diff (dataPixelSorted [:, 0 ]) != 0 , np .diff (dataPixelSorted [:, 1 ]) != 0 )
693
+ mask_sorted = np .concatenate ([np .array ([True ]).reshape ((- 1 , )), m ], axis = 0 )
694
+
695
+ mask = np .ones ((x .shape )) == 0
696
+ mask [id_orig ] = mask_sorted
697
+ mask [0 ] = True
698
+ mask [- 1 ] = True
699
+
700
+ isnan = np .logical_or (np .isnan (x ), np .isnan (y ))
701
+ mask [isnan ] = True
702
+ return mask
703
+
704
+
648
705
def getWidthHeightInPixels (fighandle , target_resolution ):
649
706
"""Target resolution as ppi / dpi. Return width and height in pixels
650
707
@@ -766,6 +823,8 @@ def opheimSimplify(x, y, tol):
766
823
return mask
767
824
768
825
826
+
827
+
769
828
def limitPrecision (fighandle , axhandle , linehandle , alpha ):
770
829
"""Limit the precision of the given data. If alpha is 0 or negative do nothing.
771
830
@@ -823,6 +882,8 @@ def limitPrecision(fighandle, axhandle, linehandle, alpha):
823
882
linehandle .set_ydata (data [:, 1 ])
824
883
825
884
885
+
886
+
826
887
def segmentVisible (data , dataIsInBox , xLim , yLim ):
827
888
"""Given a bounding box {x,y}Lim, determine whether the line between all
828
889
pairs of subsequent data points [data(idx,:)<-->data(idx+1,:)] is visible.
@@ -902,6 +963,8 @@ def corners2D(xLim, yLim):
902
963
return bottomLeft , topLeft , bottomRight , topRight
903
964
904
965
966
+
967
+
905
968
def segmentsIntersect (X1 , X2 , X3 , X4 ):
906
969
"""Checks whether the segments X1--X2 and X3--X4 intersect.
907
970
@@ -927,7 +990,7 @@ def segmentsIntersect(X1, X2, X3, X4):
927
990
928
991
929
992
def crossLines (X1 , X2 , X3 , X4 ):
930
- """
993
+ """
931
994
Checks whether the segments X1--X2 and X3--X4 intersect.
932
995
See https://en.wikipedia.org/wiki/Line-line_intersection for reference.
933
996
Given four points X_k=(x_k,y_k), k\in{1,2,3,4}, and the two lines
0 commit comments