{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Faceted Charts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Faceted charts, also known as small multiples or trellis plots, are a popular data visualization technique consisting of splitting a dataset into subsets and displays them as individual charts. Each \"facet\", or small chart, represents a combination of one or more categorical variables, allowing users to compare trends, distributions, or relationships across different categories in a structured way. For example, a faceted scatter plot might show the relationship between two continuous variables for each level of a categorical variable, such as sales performance across various regions.\n", "\n", "The primary advantage of faceted charts is their ability to break down complex datasets into digestible parts, enabling comparisons while maintaining context. They are particularly useful when analyzing data segmented by categories, such as demographic groups, time periods, or geographic areas. By organizing the visualizations in a grid or matrix, faceted charts eliminate the need for complex color coding or overlaid graphics, reducing visual clutter and making patterns easier to discern. This approach is not only aesthetically clean but also analytically robust, as it highlights nuances and variations that might be obscured in aggregate data visualizations." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting ready " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this recipe, we will use the `stocks` data set which is already available in `Plotly`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Import the `plotly.express` module as `px`" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Load the `stocks` data set from the Plotly express data submodule making sure to set the argument `indexed` to `True`" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "df = px.data.stocks(indexed=True)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
company | \n", "GOOG | \n", "AAPL | \n", "AMZN | \n", "FB | \n", "NFLX | \n", "MSFT | \n", "
---|---|---|---|---|---|---|
date | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
2018-01-01 | \n", "1.000000 | \n", "1.000000 | \n", "1.000000 | \n", "1.000000 | \n", "1.000000 | \n", "1.000000 | \n", "
2018-01-08 | \n", "1.018172 | \n", "1.011943 | \n", "1.061881 | \n", "0.959968 | \n", "1.053526 | \n", "1.015988 | \n", "
2018-01-15 | \n", "1.032008 | \n", "1.019771 | \n", "1.053240 | \n", "0.970243 | \n", "1.049860 | \n", "1.020524 | \n", "
2018-01-22 | \n", "1.066783 | \n", "0.980057 | \n", "1.140676 | \n", "1.016858 | \n", "1.307681 | \n", "1.066561 | \n", "
2018-01-29 | \n", "1.008773 | \n", "0.917143 | \n", "1.163374 | \n", "1.018357 | \n", "1.273537 | \n", "1.040708 | \n", "