> For the complete documentation index, see [llms.txt](https://time-series-features.gitbook.io/hctsa-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://time-series-features.gitbook.io/hctsa-manual/installing-and-using-hctsa/analyzing_visualizing/plotting_the_time_series.md).

# Plotting the time series

The *hctsa* package provides a simple means of plotting time series: the `TS_PlotTimeSeries` function. Its inputs are `TS_PlotTimeSeries(whatData,numPerGroup,whatTimeSeries,maxLength,plotOptions)`. The time series to plot, `whatTimeSeries`, can be `'all'`, the name of a group (in `TimeSeries.Group`), a keyword, a vector of indices, or `'grouped'` (or empty) to plot examples of each labeled group.

## Basic plotting

For example, to plot a set of time series that have not been assigned groups, we can run the following:

```
    whatData = 'norm'; % Get data from HCTSA_N.mat
    plotWhatTimeSeries = 'all'; % plot examples from all time series
    plotHowMany = 10; % how many to plot
    maxLength = 400; % maximum number of samples to plot for each time series
    plotOptions = struct('plotFreeForm',false); % plot each time series in its own subplot
    TS_PlotTimeSeries(whatData,plotHowMany,plotWhatTimeSeries,maxLength,plotOptions);
```

For an assorted set of time series (the 1000 time series of the [Empirical1000](https://doi.org/10.6084/m9.figshare.5436136) dataset, normalized into `HCTSA_N.mat`), this produces the following:

![](https://254595279-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEJuzw5fsQv4fwW3E7P%2Fuploads%2Fgit-blob-80d873eb3049cf432588b55f0ae1d3db8fcc9337%2FtimeSeriesPlot.png?alt=media)

Showing 400 samples of 10 selected time series, equally spaced through the time series in `HCTSA_N.mat` (IDs 1, 112, 223, ..., 1000). Each title gives the time series's ID (in braces), name, keywords (in square brackets), and length. In this subplot layout, a time series longer than `maxLength` is shown as a randomly positioned segment of `maxLength` samples (its range is given in the title).

## Freeform plotting

Many more custom plotting options are available by passing an options structure to `TS_PlotTimeSeries`, including the `'plotFreeForm'` option. Free-form plotting (the default, `plotFreeForm = true`) shows all time series in a single set of axes, which allows very many time series to be shown in one plot:

```
    % Plot as a freeform plot without labeling time series:
    plotOptions = struct('plotFreeForm',true,'displayTitles',false);
    TS_PlotTimeSeries('norm',40,'all',300,plotOptions);
```

![](https://254595279-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEJuzw5fsQv4fwW3E7P%2Fuploads%2Fgit-blob-a96f6b006423bb818652c8e7e9586ea07476834f%2Ffreeform_timeSeries_Plot.png?alt=media)

producing an overview picture of the first 300 samples of 40 time series (spaced through the rows of the data matrix).

Other fields of `plotOptions` (with their defaults) are: `displayTitles` (`true`), `howToFilter` (how to choose the time series to plot: `'evenly'`, `'firstcome'`, or `'rand'`; default `'evenly'`), `colorMap`, `LineWidth` (1), `newFigure` (`true`), `sortByLength` (`false`), and `carpetPlot` (`false`; plots the time series as a grayscale image).

## Dealing with groups of time series

When the time series have been assigned groups (using `TS_LabelGroups`, [here](/hctsa-manual/installing-and-using-hctsa/analyzing_visualizing/grouping.md)), this information is automatically incorporated into `TS_PlotTimeSeries`, which then plots a given number of each time series group, and colors them accordingly:

```
    numPerGroup = 5; % plot this many examples of each group of time series
    plotHow = 'grouped'; % plot examples of each assigned group of time series
    plotOptions = struct('plotFreeForm',false); % plot each time series in its own subplot
    TS_PlotTimeSeries('norm',numPerGroup,plotHow,500,plotOptions);
```

![](https://254595279-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEJuzw5fsQv4fwW3E7P%2Fuploads%2Fgit-blob-9954f52318706aebc26d757d5f69494cce80fae5%2FGroupedTimeSeriesPlot.png?alt=media)

Here we used the noisy/periodic dataset of 40 time series of length 500 (20 sums of sinusoids with added noise, keyword `noisy`, and 20 noise-free ones, keyword `periodic`), labeled using `TS_LabelGroups('norm',{'noisy','periodic'})`. The two labeled groups of time series are recognized by the function: red (`noisy`) and blue (`periodic`), and 5 time series from each group are plotted. These time series are no longer than `maxLength` (500 samples), so each is plotted in full.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://time-series-features.gitbook.io/hctsa-manual/installing-and-using-hctsa/analyzing_visualizing/plotting_the_time_series.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
