CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
ScatterPlotWidget.py65 linesDownload Raw Back to examples
1"""2Demonstration of ScatterPlotWidget for exploring structure in tabular data.3 4The widget consists of four components:5 61) A list of column names from which the user may select 1 or 2 columns7    to plot. If one column is selected, the data for that column will be8    plotted in a histogram-like manner by using pg.pseudoScatter(). 9    If two columns are selected, then the10    scatter plot will be generated with x determined by the first column11    that was selected and y by the second.122) A DataFilter that allows the user to select a subset of the data by 13    specifying multiple selection criteria.143) A ColorMap that allows the user to determine how points are colored by15    specifying multiple criteria.164) A PlotWidget for displaying the data.17 18"""19 20import numpy as np21 22import pyqtgraph as pg23 24pg.mkQApp()25 26# Make up some tabular data with structure27data = np.empty(1000, dtype=[('x_pos', float), ('y_pos', float), 28                             ('count', int), ('amplitude', float), 29                             ('decay', float), ('type', 'U10')])30strings = ['Type-A', 'Type-B', 'Type-C', 'Type-D', 'Type-E']31typeInds = np.random.randint(5, size=1000)32data['type'] = np.array(strings)[typeInds]33data['x_pos'] = np.random.normal(size=1000)34data['x_pos'][data['type'] == 'Type-A'] -= 135data['x_pos'][data['type'] == 'Type-B'] -= 136data['x_pos'][data['type'] == 'Type-C'] += 237data['x_pos'][data['type'] == 'Type-D'] += 238data['x_pos'][data['type'] == 'Type-E'] += 239data['y_pos'] = np.random.normal(size=1000) + data['x_pos']*0.140data['y_pos'][data['type'] == 'Type-A'] += 341data['y_pos'][data['type'] == 'Type-B'] += 342data['amplitude'] = data['x_pos'] * 1.4 + data['y_pos'] + np.random.normal(size=1000, scale=0.4)43data['count'] = (np.random.exponential(size=1000, scale=100) * data['x_pos']).astype(int)44data['decay'] = np.random.normal(size=1000, scale=1e-3) + data['amplitude'] * 1e-445data['decay'][data['type'] == 'Type-A'] /= 246data['decay'][data['type'] == 'Type-E'] *= 347 48 49# Create ScatterPlotWidget and configure its fields50spw = pg.ScatterPlotWidget()51spw.setFields([52    ('x_pos', {'units': 'm'}),53    ('y_pos', {'units': 'm'}),54    ('count', {}),55    ('amplitude', {'units': 'V'}),56    ('decay', {'units': 's'}),    57    ('type', {'mode': 'enum', 'values': strings}),58    ])59    60spw.setData(data)61spw.show()62 63if __name__ == '__main__':64    pg.exec()65 
Aluode/PerceptionLabPortable · CoolFace