def data(self, newdata): if newdata == None: return None self._data = newdata # When data changes, update the list of renderers renderers = suitable_renderers(self.data) combobox = self.renderer_combobox previous_selection = combobox.currentIndex( ) # remember previous choice try: #Attempt to keep the same range previous_view_rect = self.figure_widget.figureWidget.viewRect() except AttributeError: previous_view_rect = None combobox.clear() for i, renderer in enumerate(renderers): combobox.addItem(renderer.__name__, renderer) # Attempt to keep the same renderer as we had before - or use the # "best" one. NB setting the current index will trigger the renderer # to be created in renderer_selected try: if previous_selection == 0: raise ValueError( ) # if we didn't choose the last renderer, just # pick the best one. Otherwise, try to use the same # renderer as we used before else: index = renderers.index(self.renderer.__class__) combobox.setCurrentIndex(index) try: self.renderer_selected(index) except Exception as e: print 'The selected renderer failed becasue', e except ValueError: combobox.setCurrentIndex(0) self.renderer_selected(0) if previous_view_rect != None: try: self.figure_widget.figureWidget.setRange(previous_view_rect, padding=0) except AttributeError: pass
# -*- coding: utf-8 -*- """ Created on Tue Oct 27 13:09:09 2015 @author: rwb27 """ import nplab import numpy as np import matplotlib.pyplot as plt from numpy.random import random from nplab.ui.data_renderers import suitable_renderers if __name__ == '__main__': df = nplab.current_datafile() group = df.create_group("test_items") d = group.create_dataset("1d_generic",data=random((100))) print suitable_renderers(d) d = group.create_dataset("2d_generic",data=random((100,100))) print suitable_renderers(d) d = group.create_dataset("3d_rgb",data=random((100,100,3))) print suitable_renderers(d) d = group.create_dataset("3d_generic",data=random((100,100,100))) print suitable_renderers(d) df.show_gui(block=True) df.close()
# -*- coding: utf-8 -*- """ Created on Tue Oct 27 13:09:09 2015 @author: rwb27 """ from __future__ import print_function import nplab # import numpy as np # import matplotlib.pyplot as plt from numpy.random import random from nplab.ui.data_renderers import suitable_renderers if __name__ == '__main__': df = nplab.current_datafile() group = df.create_group("test_items") d = group.create_dataset("1d_generic", data=random((100))) print(suitable_renderers(d)) d = group.create_dataset("2d_generic", data=random((100, 100))) print(suitable_renderers(d)) d = group.create_dataset("3d_rgb", data=random((100, 100, 3))) print(suitable_renderers(d)) d = group.create_dataset("3d_generic", data=random((100, 100, 100))) print(suitable_renderers(d)) df.show_gui(block=True) df.close()