# A Comprehensive Guide to Visualizing High\-Dimensional Data with Parallel Coordinates Plots

- Canonical: https://33rdsquare.com/visualize-data-using-parallel-coordinates-plot/
- Published: 2024-09-03
- Author: Jordan Brown
- Categories: [Artificial Intelligence & Machine Learning & ChatGPT](https://33rdsquare.com/category/tech/ai/)

---

When working with multivariate datasets containing many numerical variables, it can be challenging to visualize relationships between all the variables at once. While scatterplot matrices and heat maps are useful for pairwise comparisons, they become overwhelming as the number of variables increases.

Parallel coordinates plots provide a compact way to display observations across multiple variables in a single two-dimensional visualization. In this post, we‘ll take an in-depth look at parallel coordinates plots including how they work, best practices for constructing them, and how to create them using Python. We‘ll also compare them to other multivariate visualization techniques and discuss when they may be most useful.

## What are Parallel Coordinates Plots?

A parallel coordinates plot is a way to visualize multivariate numerical data. Each variable is represented by a vertical axis, and each observation or sample is represented by a polyline that traverses the axes. All the axes are placed in parallel, evenly spaced apart.

The position of the polyline at each axis indicates the value of that variable for that observation. Parallel coordinates plots allow you to see both the individual values for each observation across all variables as well as overall patterns, trends, and relationships between the variables.

Here is an example parallel coordinates plot of the famous Iris flower dataset, showing measurements of sepal length, sepal width, petal length, and petal width for 150 iris flowers:

[Iris parallel coordinates plot image]

From this plot, we can immediately see some interesting patterns:

- Setosa flowers have the smallest petal lengths and widths but the largest sepal widths
- Versicolor and virginica flowers have larger and more varied petal and sepal sizes
- Petal length and petal width appear to be highly correlated, forming distinct clusters for each species

## Anatomy of a Parallel Coordinates Plot

Let‘s break down the main components of a parallel coordinates plot in more detail:

**Axes**: Each variable is represented by a vertical axis. All the axes are parallel and equidistant from each other. The scale of each axis is proportional to the range of values for that variable. Axes are usually labeled with the variable name.

**Polylines**: Each observation is represented by a polyline (or path) that connects its values on each axis. The position of the line at each axis intersection indicates the value for that variable. Steep line segments between two axes indicate a strong relationship between those variables for that observation.

**Scaling**: Axes can have different units and magnitudes. To make the polylines comparable, each axis should be scaled independently to a common range, usually 0 to 1. This puts all variables on a similar scale regardless of their original units and magnitudes. However, the relative positions and slopes of the lines are preserved.

**Ordering**: The order of the axes can greatly impact the interpretability of a parallel coordinates plot. Adjacent axes should be arranged to highlight meaningful relationships and minimize unnecessary line crossings. Variables with strong correlations should be placed next to each other. Ordering can be optimized manually or using algorithms like hierarchical clustering.

**Brushing**: Many parallel coordinates plots support brushing, which means you can click and drag along an axis to highlight observations in a certain range. The corresponding polylines will be emphasized, allowing you to see where those observations fall on the other variables. Brushing is an important interactive feature for exploring subsets of the data.

## Constructing Effective Parallel Coordinates Plots

While parallel coordinates plots are a powerful tool, they need to be constructed thoughtfully to be effective. Here are some best practices to keep in mind:

**Normalize or standardize variables**: Variables should be transformed to a common scale, usually 0 to 1 or -1 to 1, so their axes are comparable. This prevents variables with larger magnitudes from dominating the visual space.

**Optimize axis order**: Arrange the axes to emphasize important comparisons and relationships. Place highly correlated variables next to each other. Minimize line crossings that don‘t encode meaningful patterns. Experiment with different orderings to find the most insightful arrangement.

**Limit the number of variables**: Too many axes will make the plot cluttered and difficult to interpret. Consider dimensionality reduction techniques like PCA to consolidate correlated variables. Focus on the most informative variables for the relationships you want to highlight.

**Use color and opacity**: Color the polylines consistently by a meaningful categorical variable like class label. This will emphasize clustering and separability between groups. Decrease the opacity of the lines to help with overplotting when there are many observations.

**Support brushing and linking**: Allow the user to brush observations by clicking and dragging on the axes. Highlight the brushed polylines and link them to other coordinated views like scatterplots or data tables. This facilitates interactive exploration of subsets and outliers.

**Provide clear labeling**: Label the axes legibly with the variable names and units. Provide a legend for the color scale. Use tooltips to show the exact values when hovering over polylines. Make sure the text is readable and not obscured by the lines.

## Creating Parallel Coordinates Plots in Python

Several Python libraries support creating parallel coordinates plots, including Matplotlib, Seaborn, Plotly, and Altair. Here we‘ll show examples using Plotly, which provides a highly customizable and interactive plotting interface.

First, let‘s create a parallel coordinates plot of the Iris dataset using Plotly Express:

```
import plotly.express as px

df = px.data.iris()
fig = px.parallel_coordinates(
    df,
    color="species_id",
    labels={
        "species_id": "Species",
        "sepal_width": "Sepal Width",
        "sepal_length": "Sepal Length",
        "petal_width": "Petal Width",
        "petal_length": "Petal Length",
    },
    color_continuous_scale=px.colors.diverging.Tealrose,
    color_continuous_midpoint=2
)
fig.show()
```

This code loads the built-in Iris dataset, maps the species to color, customizes the axis labels, and displays the plot. The `color_continuous_midpoint` argument sets the middle value of the color range to better distinguish the three species.

Here‘s the resulting plot:

[Plotly Express Iris plot]

We can see how Plotly automatically scales the axes, adds brushing functionality, and displays a hover tooltip with the values for each polyline. The three species form distinct color-coded clusters, with setosa clearly separated from the other two.

For even more customization, we can use Plotly Graph Objects:

```
import plotly.graph_objects as go

fig = go.Figure(data=
    go.Parcoords(
        line = dict(color = df[‘species_id‘],
                   colorscale = [[0,‘purple‘],[0.5,‘lightseagreen‘],[1,‘gold‘]]),
        dimensions = list([
            dict(range = [df[‘sepal_length‘].min(),df[‘sepal_length‘].max()],
                constraintrange = [4,8],
                label = ‘Sepal Length‘, values = df[‘sepal_length‘]),
            dict(range = [df[‘sepal_width‘].min(),df[‘sepal_width‘].max()],
                label = ‘Sepal Width‘, values = df[‘sepal_width‘]),
            dict(range = [df[‘petal_length‘].min(), df[‘petal_length‘].max()],
                label = ‘Petal Length‘, values = df[‘petal_length‘]),
            dict(range = [df[‘petal_width‘].min(),df[‘petal_width‘].max()],
                label = ‘Petal Width‘, values = df[‘petal_width‘])
        ])
    )
)

fig.update_layout(
    plot_bgcolor = ‘white‘,
    paper_bgcolor = ‘white‘
)

fig.show()
```

Here we define each axis as a dictionary specifying its range, label, and values. We can constrain brushing to a range within the total variable range, in this case limiting the sepal length brush to between 4 and 8 cm.

We also have full control over the color scale, opting for a custom 3-point scale that maps to the three species. Finally, we set the plot and paper background color to white for better contrast.

Here‘s the resulting plot:

[Plotly Graph Objects Iris plot]

With a bit more work, we gain finer control over the plot‘s appearance and functionality. The general structure and patterns remain the same, but the plot is more polished and readable.

## Comparison to Other Multivariate Visualization Techniques

Parallel coordinates plots are just one of many techniques for visualizing multivariate data. Let‘s briefly compare them to some other common approaches:

**Scatterplot Matrices**: A scatterplot matrix shows all the pairwise scatterplots between variables in a grid. It‘s useful for seeing the correlations and distributions between any two variables. However, it becomes unwieldy as the number of variables grows, requiring n^2 subplots for n variables. It also doesn‘t directly show relationships between more than two variables at a time.

**Heat Maps**: A heat map encodes the values of a 2D matrix as colors in a grid. It‘s often used to visualize correlation matrices, showing the pairwise correlations between all variables. Like scatterplot matrices, heat maps are limited to pairwise comparisons and don‘t scale well to high dimensions.

**Dimensionality Reduction**: Techniques like PCA, t-SNE, and UMAP aim to reduce high-dimensional data to a lower-dimensional representation that preserves important patterns. The resulting 2D or 3D embeddings can be visualized as scatterplots, revealing clusters and outliers. However, the individual variables and their relationships are not directly represented in the final plot.

Compared to these methods, parallel coordinates have several advantages:

- They show all the variables and observations in a single plot, regardless of the number of dimensions
- They directly encode the values of each observation across all variables
- They reveal relationships between adjacent variables through the line slopes
- They scale better to higher dimensions than scatterplot matrices and heat maps

However, parallel coordinates also have some limitations:

- They can become cluttered and hard to read with too many observations or variables
- They don‘t show the joint distributions or correlations between non-adjacent variables
- They require careful axis ordering and scaling to reveal meaningful patterns
- They may be unfamiliar or unintuitive to audiences not used to reading them

## When to Use Parallel Coordinates Plots

Parallel coordinates plots are a valuable tool to have in your data visualization toolbox, but they‘re not always the best choice. They tend to be most useful when:

- You have a multivariate dataset with many numerical variables (say 5-20)
- You want to compare observations across all variables simultaneously
- You want to see the relationships between adjacent variables
- You want to identify clusters, trends, and outliers across multiple dimensions
- You have a relatively small number of observations (up to a few thousand)

Some specific applications where parallel coordinates shine include:

- Visualizing high-dimensional data like sensor readings, environmental measurements, or medical records
- Comparing the profiles of different groups or categories, such as customer segments or product lines
- Exploring the parameter space of machine learning models or simulations
- Identifying multivariate outliers or anomalies that are hard to detect in lower dimensions

On the other hand, parallel coordinates may not be the best choice when:

- You have only a few variables (less than 5), in which case scatterplots or heat maps may be simpler
- You have a very large number of observations (more than a few thousand), leading to excessive overplotting
- Your audience is unfamiliar with reading parallel coordinates and needs a more intuitive representation
- You need to show precise values or distributions rather than overall patterns and comparisons

## Conclusion

Parallel coordinates plots are a powerful and underused technique for visualizing multivariate data. By representing each variable as a parallel axis and each observation as a polyline, they provide a compact and holistic view of high-dimensional datasets.

When constructed with care and best practices, parallel coordinates can reveal clusters, correlations, and outliers that are hard to see in other representations. They are especially useful for comparing observations across many variables at once and seeing the relationships between adjacent dimensions.

Python libraries like Plotly make it easy to create interactive parallel coordinates plots that support brushing, linking, and hover tooltips for deeper exploration. While not always the right choice, parallel coordinates are a valuable tool to consider when faced with a high-dimensional dataset.

The key to effective parallel coordinates is experimentation and iteration. Try different axis orderings, color schemes, and scalings to find the most meaningful patterns. Combine them with other multivariate techniques like scatterplot matrices and dimensionality reduction to gain multiple perspectives. And always keep your audience and goals in mind when deciding how to visualize your data.

With practice and an open mind, parallel coordinates can help you discover insights and communicate findings in your high-dimensional data. Give them a try on your next multivariate analysis project!

_All code examples and plots created by the author. Iris dataset sourced from scikit-learn._

### References and Further Reading

- Inselberg, A. (2009). Parallel Coordinates: Visual Multidimensional Geometry and Its Applications. Springer.
- Heinrich, J., & Weiskopf, D. (2013). State of the art of parallel coordinates. Eurographics State of the Art Reports, 2013, 95-116.
- Plotly Documentation: Parallel Coordinates Plot
- Matplotlib Documentation: Plotting with Parallel Coordinates
- Altair Documentation: Parallel Coordinates

---

Source: [A Comprehensive Guide to Visualizing High\-Dimensional Data with Parallel Coordinates Plots](https://33rdsquare.com/visualize-data-using-parallel-coordinates-plot/)
