Python package for selecting data manually on a scatter plot.
The DashLassoDataSelector is a feature of the manual_data_selector package, providing an interactive way to select data from a scatter plot using a lasso tool. This guide describes how to use the DashLassoDataSelector in your projects.
Install the manual_data_selector package using pip:
pip install manual_data_selectorFollow these steps to use the DashLassoDataSelector:
(Alternatively the 'LassoDataSelector' can be used, but this can't handle larger datasets))
-
Import the Class:
Import the
DashLassoDataSelectorclass from themanual_data_selectorpackage.from manual_data_selector.dash_lasso_data_selector import DashLassoDataSelector
-
Create an Instance:
Create an instance of DashLassoDataSelector. You'll need to pass your DataFrame as an argument, and you can optionally specify the figure size and marker size.
# Assuming 'df' is your DataFrame # Create a Dash app instance app = dash.Dash(__name__) # Create a DashLassoDataSelector instance and run it dash_app = DashLassoDataSelector(df, app, fig_size=(1600, 600), marker_size=5,port=8000)
-
Run and display the Selector:
Run the dash_app method to display the interactive scatter plot. This plot allows you to select data using the lasso tool.
dash_app.run()
The DashLassoDataSelector class provides several attributes to access the data selected through the interactive scatter plot:
-
selected_data: This attribute holds the DataFrame of the data currently selected in the scatter plot. It updates dynamically as new selections are made. -
confirmed_data: This attribute contains the DataFrame of the last confirmed data. It represents the data that was selected when the user last clicked the 'Confirm Selection' button. -
all_confirmed_data: This attribute is a dictionary of DataFrames, where each entry corresponds to a set of data confirmed by the user at different times. Every time the user clicks 'Confirm Selection', the selected data at that moment is stored as a new entry in this dictionary.
Below is a complete example demonstrating how to use the DashLassoDataSelector in your project
(the notebooks folder contains this example with a synthetic dataset):
from manual_data_selector.dash_lasso_data_selector import DashLassoDataSelector
import dash
# Create a Dash app instance
app = dash.Dash(__name__)
# Create a DashLassoDataSelector instance and run it
# Replace 'df' with your DataFrame
dash_app = DashLassoDataSelector(df, app, fig_size=(1600, 600), marker_size=5,port=8000)
dash_app.run()
# After making a selection and clicking 'Confirm Selection',
# you can access the selected data in various ways:
# The data currently selected in the plot
current_data = dash_app.selected_data
# The last set of data confirmed by the user
last_confirmed_data = dash_app.confirmed_data
# All sets of data confirmed by the user over time
all_confirmed_data = dash_app.all_confirmed_data
#transform all selected data into one dataframe
selected_data = pd.concat([dash_app.all_confirmed_data[i] for i in list(dash_app.all_confirmed_data.keys())])Below the Figures illustrating the use of the DashLassoDataSelector are shown
This figure shows the initial scatter plot from which data is selected.
This figure demonstrates how to activate the selection of data points using the lasso tool.
This figure illustrates the process of selecting data points using the lasso tool. To perform a selection, press and hold the left mouse button while drawing around the desired data points.
Confirm selection of step 3. If you want to add more data, repeat steps 2-4 untill all desired data is selected and confirmed.
This figure shows the data points that have been selected through Steps 2-4.




