Creating Multiple Scatter Traces in a Single Plot
Explore how to build multiple scatter traces in a single Plotly plot using both graph_objects and Plotly Express. Learn to filter data subsets and customize line and marker styles for clearer comparisons across categories. This lesson helps you decide between ease of use and customization when creating interactive scatterplots in data apps.
We'll cover the following...
We will mostly be focusing on using Plotly Express as much as possible because of
its convenience. It’s still very important to know how to work with Figure objects since we will encounter many situations in which we’ll need to work with them, especially when we have a lot of customizations to make. Also, keep in mind that, although the most important chart types are supported by Plotly Express, not all of them are.
Creating traces using the graph_objects module
Let’s extend the preceding chart with traces of other countries and compare the two approaches. We start with the graph_objects module’s Figure object.
- Line 2: We create a
countrieslist to filter with. - Lines 5–8: We create a subset of
poverty, which we will calldf, in which the values of theCountry Namecolumn are in thecountrieslist (using theisin method). We then extract theyear,Country Name, and