@@ -1509,42 +1509,18 @@ def __init__(self,
1509
1509
--------
1510
1510
.. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
1511
1511
"""
1512
- if positions is None :
1513
- raise ValueError ('positions must be an array-like object' )
1514
- # Force a copy of positions
1515
- positions = np .array (positions , copy = True )
1516
- segment = (lineoffset + linelength / 2. ,
1517
- lineoffset - linelength / 2. )
1518
- if positions .size == 0 :
1519
- segments = []
1520
- elif positions .ndim > 1 :
1521
- raise ValueError ('positions cannot be an array with more than '
1522
- 'one dimension.' )
1523
- elif (orientation is None or orientation .lower () == 'none' or
1524
- orientation .lower () == 'horizontal' ):
1525
- positions .sort ()
1526
- segments = [[(coord1 , coord2 ) for coord2 in segment ] for
1527
- coord1 in positions ]
1528
- self ._is_horizontal = True
1529
- elif orientation .lower () == 'vertical' :
1530
- positions .sort ()
1531
- segments = [[(coord2 , coord1 ) for coord2 in segment ] for
1532
- coord1 in positions ]
1533
- self ._is_horizontal = False
1534
- else :
1535
- cbook ._check_in_list (['horizontal' , 'vertical' ],
1536
- orientation = orientation )
1537
-
1538
1512
LineCollection .__init__ (self ,
1539
- segments ,
1513
+ [] ,
1540
1514
linewidths = linewidth ,
1541
1515
colors = color ,
1542
1516
antialiaseds = antialiased ,
1543
1517
linestyles = linestyle ,
1544
1518
** kwargs )
1545
-
1519
+ self . _is_horizontal = True # Initial value, may be switched below.
1546
1520
self ._linelength = linelength
1547
1521
self ._lineoffset = lineoffset
1522
+ self .set_positions (positions )
1523
+ self .set_orientation (orientation )
1548
1524
1549
1525
def get_positions (self ):
1550
1526
"""
@@ -1554,24 +1530,18 @@ def get_positions(self):
1554
1530
return [segment [0 , pos ] for segment in self .get_segments ()]
1555
1531
1556
1532
def set_positions (self , positions ):
1557
- """Set the positions of the events to the specified value."""
1558
- if positions is None or (hasattr (positions , 'len' ) and
1559
- len (positions ) == 0 ):
1560
- self .set_segments ([])
1561
- return
1562
-
1533
+ """Set the positions of the events."""
1534
+ if positions is None :
1535
+ positions = []
1536
+ if np .ndim (positions ) != 1 :
1537
+ raise ValueError ('positions must be one-dimensional' )
1563
1538
lineoffset = self .get_lineoffset ()
1564
1539
linelength = self .get_linelength ()
1565
- segment = (lineoffset + linelength / 2. ,
1566
- lineoffset - linelength / 2. )
1567
- positions = np .asanyarray (positions )
1568
- positions .sort ()
1569
- if self .is_horizontal ():
1570
- segments = [[(coord1 , coord2 ) for coord2 in segment ] for
1571
- coord1 in positions ]
1572
- else :
1573
- segments = [[(coord2 , coord1 ) for coord2 in segment ] for
1574
- coord1 in positions ]
1540
+ pos_idx = 0 if self .is_horizontal () else 1
1541
+ segments = np .empty ((len (positions ), 2 , 2 ))
1542
+ segments [:, 0 , pos_idx ] = segments [:, 1 , 0 ] = np .sort (positions )
1543
+ segments [:, 0 , 1 - pos_idx ] = lineoffset + linelength / 2
1544
+ segments [:, 1 , 1 - pos_idx ] = lineoffset - linelength / 2
1575
1545
self .set_segments (segments )
1576
1546
1577
1547
def add_positions (self , position ):
0 commit comments