Aug 2, 2023 5 MIN

Introducing Charting Overlays with Hold On

Learn how 'Hold On' in OpenBB Terminal 3.2.0 streamlines data analysis by effortlessly overlaying time series for easy comparison. Enhance your charting capabilities today!

blog hero

How it all started

One of my personal pet peeves with the OpenBB Terminal, and the single biggest user request since the Gamestonk Terminal days, has been the ability to overlay different time series.

Throughout our history, we have added some implicit ways to do this.

Economy had stored datasets that could be plotted on two different axes, but that was limited to datasets there (granted we saw some creative problem-solving from the community). Forecasting and QA menus had plotting functionalities, but nothing to overlay.

When OpenBB Terminal 3.0 was launched, and we completely overhauled charting, we introduced the ability to add traces from saved files onto the charts from our command outputs.

While this was a massive improvement, I remained dissatisfied with the workflow of having to run cmd1 --export/cmd2, then interact with the PyWry window and go through the process for each time series. For more information, see the PyWry announcement blog post here.

During this time, I reminisced about my previous coding experience in MatLab, and it hit me! In MatLab, each plot opens up a new figure window, just like the OpenBB Terminal. However, when you want to add multiple charts, you run the command hold. See the documentation here.

x = linspace(0,5,100);
y1 = besselj(0,x);
y2 = besselj(1,x);
plot(x,y1)
hold on
plot(x,y2)

So, why couldn't we just do that? I will dive into the specifics at the end of this post, but the short answer is that there was no reason why we couldn't.

How does "Hold on" work?

From any location in the terminal, the command hold on can be executed.

Unlike MatLab, this command does not apply to a previously existing figure; instead, it tells the terminal to start a blank canvas for your chart. Any subsequent terminal command that returns a chart will populate that figure on a new axis.

Running hold off releases the figure and sends it to your PyWry window. Additionally, "hold off" has an optional --title flag that will populate the figure title when sent. This is perfect for comparing time series with different orders of magnitudes.

For example, to analyze the US Unemployment Rate (which is on the order of 10) and the S&P500 Index (which is on the order of multiple thousands) starting from 2015, we can run the following command pipeline:

economy/hold on/cpi -s 2015-01-01/index -i sp500 -s 2015-01-01/hold off

This produces the following figure, where we can observe the CPI YoY % change on the primary right axis and the S&P500 index on the left axis, color-coordinated to the chart.

Interactive Chart - CPI YoY % and S&P500

This was the initial implementation, but there were a few issues.

Issue #1 - Legends

The first issue was that the legends were not always intuitive.

By default, we populate the legend with the command run. When just 2 lines are added, this likely suffices, but if I have multiple outputs from the same commands, it is easy to get lost in determining which line corresponds to which arguments.

To address this, it made sense to allow the figure to be updated with any custom legend. The resolution was to enable any function to have a --legend option, but only when the hold state is on.

As an example, to plot revenues for two companies on the same plot and distinguish the legends, we would run:

stocks/fa/hold on/income -t AAPL -q -l 40 --plot revenue --legend AAPL/income -t MSFT -q -l 40 --plot revenue --legend MSFT/hold off --title Comparing Revenue with hold on
Comparing Revenue with hold on

This gives us the custom legend so we can identify which company is associated with each trace.

Issue #2 - Same axis

In the previous example, it is nice to see how they are both increasing linearly, but if I wanted to see a comparison of the absolute value, then I want them on the same axis. To achieve this, we added a --sameaxis argument to the hold on command, so that any subsequent plots are on the same axis.

To illustrate how workflows can be automated with this functionality, I will use an OpenBB routine:

$STOCKS=AAPL,AMZN,MSFT,TSLA,GOOG
stocks
fa
hold on --sameaxis
foreach $$tick in $STOCKS:
   income -t $$tick -l 40 -q --plot revenue --legend $$tick revenue
end
hold off --title FAANG Revenues 10 Year

What this does is define a list of tickers, in this case FAANG.

We navigate to stocks/fa and hold on our figure, with the --sameaxis specified. Using the OpenBB routine functions, we loop through the FAANG tickers, plotting 10 years of quarterly revenues and labeling each trace as "ticker revenue" for each ticker (i.e APPL revenue).

After the loop we show the plot with hold off, this time specifying the title to be “FAANG Revenues 10 Year”. If this is in a file called revenue.openbb, we launch this script with exe --file revenue.openbb and this will result in the following figure:

FAANG Revenues 10 Year

Give it a go on OpenBB Terminal 3.2.0, and feel free to share your valuable feedback with us. We'd love to hear what you think and see some of the fantastic work you create!

Experience it for free here and unlock the potential of seamless data analysis.

Explore the
Terminal Pro


We use cookies

This website uses cookies to meausure and improve your user experience.