Trusted answers to developer questions

Ravi

**Andrews curves** visualize multidimensional/high-dimensional data by mapping each observation onto a function. This function is defined as follows:

- The $x$ coefficients represent the values of each dimension.
- The $n$ is linearly spaced between $-\pi$ and $+\pi$.

Andrews curves have been known to retain means, distance (up to a constant), and variances. As a result, Andrews curves represented by closely spaced functions imply that the accompanying data points will be closely spaced.

`andrews_curves()`

method in pandasThe ** andrews_curves() method** in pandas is used to plot Andrews curves on a DataFrame. Each frame row represents a single curve.

```
pandas.plotting.andrews_curves(frame, class_column, ax=None, samples=200, color=None, colormap=None, **kwargs)
```

: This is the DataFrame to plot.`frame`

: This is the name of the column containing class names.`class_column`

: This is the`ax`

`matplotlib`

axes object.: This corresponds to the number of points to plot in each curve.`samples`

: This parameter can be a list or tuple of colors that can be used for different classes.`color`

: This can be a string or a`colormap`

`matplotlib`

object where colors can be selected from the colormap.

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv( 'https://raw.github.com/pandas-dev/' 'pandas/main/pandas/tests/io/data/csv/iris.csv' ) print(df.head()) pd.plotting.andrews_curves(df, 'Name') plt.show()

Plotting Andrews curves using Pandas library in Python

- Lines 1–2: We import the
`pandas`

and`matplotlib`

packages. - Lines 4–7: We read the iris dataset into a DataFrame called
`df`

. - Line 8: The sample data from
`df`

is printed. - Line 9: We plot the Andrews curves using the
`andrews_curves()`

method. Here, the`Name`

column in the dataset/DataFrame is a categorical column consisting of class names. - Line 10: We display the plotted graph.

RELATED TAGS

pandas

python

CONTRIBUTOR

Ravi

RELATED COURSES

View all Courses

Keep Exploring

Related Courses