@@ -226,6 +226,27 @@ def setZ(self, z):
226226 self ._z_mapping = np .argsort (z )
227227 self ._inv_mapping = np .argsort (self ._z_mapping )
228228
229+ def setCoordinates (self , x , y ):
230+ """
231+ Change the coordinates of points while keeping other properties.
232+
233+ Asserts that the number of points stays the same.
234+
235+ Note. Pyqtgraph does not offer a method for this: setting coordinates
236+ invalidates other data. We therefore retrieve the data to set it
237+ together with the coordinates. Pyqtgraph also does not offer a
238+ (documented) method for retrieving the data, yet using
239+ data[prop]` looks reasonably safe.
240+
241+ The alternative, updating the whole scatterplot from the Orange Table,
242+ is too slow.
243+ """
244+ assert len (self .data ) == len (x ) == len (y )
245+ data = dict (x = x , y = y )
246+ for prop in ('pen' , 'brush' , 'size' , 'symbol' , 'data' ):
247+ data [prop ] = self .data [prop ]
248+ self .setData (** data )
249+
229250 def updateSpots (self , dataSet = None ): # pylint: disable=unused-argument
230251 self ._update_spots_in_paint = True
231252 self .update ()
@@ -662,8 +683,8 @@ def update_jittering(self):
662683 x , y = self .get_coordinates ()
663684 if x is None or len (x ) == 0 or self .scatterplot_item is None :
664685 return
665- self ._update_plot_coordinates ( self . scatterplot_item , x , y )
666- self ._update_plot_coordinates ( self . scatterplot_item_sel , x , y )
686+ self .scatterplot_item . setCoordinates ( x , y )
687+ self .scatterplot_item_sel . setCoordinates ( x , y )
667688 self .update_labels ()
668689
669690 # TODO: Rename to remove_plot_items
@@ -843,27 +864,6 @@ def _jitter_data(self, x, y, span_x=None, span_y=None):
843864 return (x + magnitude * span_x * rs * np .cos (phis ),
844865 y + magnitude * span_y * rs * np .sin (phis ))
845866
846- def _update_plot_coordinates (self , plot , x , y ):
847- """
848- Change the coordinates of points while keeping other properites.
849-
850- Asserts that the number of points stays the same.
851-
852- Note. Pyqtgraph does not offer a method for this: setting coordinates
853- invalidates other data. We therefore retrieve the data to set it
854- together with the coordinates. Pyqtgraph also does not offer a
855- (documented) method for retrieving the data, yet using
856- `plot.data[prop]` looks reasonably safe. The alternative, calling
857- update for every property would essentially reset the graph, which
858- can be time consuming.
859- """
860- assert self .n_shown == len (x ) == len (y )
861- data = dict (x = x , y = y )
862- for prop in ('pen' , 'brush' , 'size' , 'symbol' , 'data' ,
863- 'sourceRect' , 'targetRect' ):
864- data [prop ] = plot .data [prop ]
865- plot .setData (** data )
866-
867867 def update_coordinates (self ):
868868 """
869869 Trigger the update of coordinates while keeping other features intact.
@@ -891,8 +891,8 @@ def update_coordinates(self):
891891 self .plot_widget .addItem (self .scatterplot_item_sel )
892892 self .plot_widget .addItem (self .scatterplot_item )
893893 else :
894- self ._update_plot_coordinates ( self . scatterplot_item , x , y )
895- self ._update_plot_coordinates ( self . scatterplot_item_sel , x , y )
894+ self .scatterplot_item . setCoordinates ( x , y )
895+ self .scatterplot_item_sel . setCoordinates ( x , y )
896896 self .update_labels ()
897897
898898 self .update_density () # Todo: doesn't work: try MDS with density on
0 commit comments