Show Sidebar Hide Sidebar

Applying Filters in Plotly 2.0

Filter Data in Plotly 2.0

Step 1

Introduction

Understanding how to apply filters to data in Plotly 2.0 can be divided in three categories: (1) categorical data, (2) continuous data, and (3) dates. As a consequences, we will look at these individually and in the order previously specified. It is also important to note, that in Plotly 2.0 you can apply single or multiple filters to each plot.

Keeping that in mind, we will explore the meteorite dataset and by applying filters we will attempt to answer the question: 'Where has the largest concentraction of ordinary meteorites greater than 10,000 grams fallen in the 21st century?'

Step 2

Try an Example

You can use the data featured in this tutorial by clicking on 'Open This Data in Plotly' on the left-hand side. It'll open in your workspace.

Open data

Step 3

Add Your Data to Plotly

For this tutorial, copy the meteorite dataset URL https://raw.githubusercontent.com/bcdunbar/datasets/master/meteorites_subset.csv and head to Plotly’s new online workspace and add your data by entering the meteorite URL.

If you decide to try another dataset, keep in mind that Plotly accepts .xls, .xlsx, or .csv files. For more information on how to enter your data, see this tutorial.

insert

Step 4

Create Chart

First we need to create a chart! As we are plotting meteorite locations we will create a scatter map. Thus, under 'Chart Type' select 'Satellite Maps'.

insert

Immediately below, click the 'Latitude' dropdown and select the column name 'recatlat', then click the 'Longtitude' dropwdown and select column name 'recatlon'.

insert

Step 5

Style Chart

Like many other charts, here you can apply numerous styles to your chart but for the purpose of this tutorial we have decided to just change the marker opacity. To do this, simply click 'Traces' under the 'STYLE' tab and in the text box next to 'marker opacity' enter '0.5'.

insert

Step 6

Filter Categorical Data

To apply a filter, click 'filter' under the 'GRAPH' tab. Now, you should see the blue ‘+Filter’ button in the top-right of the next panel. Click it! This will produce a filter box directly below the button in the panel.

insert

Here, you can choose the column which you want to filter; click the dropdown next to ‘Select Column’ and select 'class'.

insert

A new box ought to have appeared. Here, click the dropdown next to ‘Traces To Filter’. You can select a single variable or multiple. For the purpose of this tutorial, select 'reclong'.

insert

Next, click the dropdown beside ‘Operator’ and choose one of the operators (i.e. ‘Matching Values’).

insert

The final dropdown will allow you to select unique values from the column which you have opted to filter. You have the option to either use “Include” –only display the unique values you have selected – or “Exclude” – the opposite of include. Here, we will include the class value 'Ordinary'.

insert

Congratulations, you have successful applied a filter to categorical data.

Step 7

Filter Continuous Data

Like previously, click the blue ‘+Filter’ button in the top-right of the next panel. This ought to produce a filter box directly below the categorical filter that was just applied.

insert

Again, similar to before, you can choose the column which you want to filter; click the dropdown next to ‘Select Column’ and select the 'mass (g)'.

insert

A new box ought to have appeared. Here, click the dropdown next to ‘Traces To Filter’. You can select a single variable or multiple. For this filter, we will select 'reclong' again.

insert

Next, click the dropdown beside ‘Operator’ and choose one of the operators (i.e. ‘Inequality’).

insert

The final dropdown will allow you to filter data by one of the four available inequalities (less than, greater than, less than and equal to, greater than and equal to). To answer our question that we've set out to visualise, select 'greater than' and enter '10000' (greater than 10,000 grams).

insert

Congratulations, you have successful applied a filter to continuous data.

Step 8

Filter Date Data

In addition to categorical and continuous data, we can apply filters to dates. Like previously, you should see the blue ‘+Filter’ button in the top-right of the next panel. Click it! This ought to produce another filter box directly below the other filters.

insert

Here, you can choose the date data column that you want to filter; click the dropdown next to ‘Select Column’ and select the 'year'.

insert

A new box ought to have appeared. Here, click the dropdown next to ‘Traces To Filter’. You can select a single variable or multiple for which you want to apply the filter to. Like before, we will select 'reclong'.

insert

Next, click the dropdown beside ‘Operator’ and choose the operator ‘Range’

insert

Immediately below, you have the option to set both the ‘Min’ (minimum) and ‘Max’ (maximum) values of the range. In this tutorial, we have entered the values 2015-01-01 and 2016-01-01 respectively. Additionally, there is the option to either use “Include X” –only display the unique values you have selected – or “Exclude X” – the opposite of include.

insert

Congratulations, you have successful applied a filter to date data.

Step 9

Final Result

Below is the final result from applying three (categorical, continuous, and date) filters. Thus, you can see that by applying these filter we can answer the question that we orginally set out to visualise: Where has the concentraction of ordinary meteorites greater than 10,000 grams fallen in the 21st century?

insert

Step 10

Save and Share

Your chart is now done! Click SAVE on the left-hand side.

insert

After giving your file a name, select your PLOT and DATA as 'Public' or 'Private'. For more information on how sharing works, including the difference between private, public and secret sharing, visit this page.

insert

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to our Premium or Enterprise plans.