Skip to main content

Use a scatter plot overlay to create real-time chart markers

· 2 min read
Stable diffusion prompt: marker drawing on a scatter plot, written notes, line plot, graph, chart with dots on the lines Seed-2953402 Steps-25 Guidance-7.5
Chip Kent
See your buys, sells, and predictions in real time

On Deephaven Community Slack, we frequently get interesting questions from users. Recently, a user asked us how to draw markers on a chart. In his case, he wanted to plot financial predictions with markers when his automated trading system bought or sold a stock or option.

Drawing markers is easy, but it may not be obvious until you have seen it once. To draw markers on a chart, you need to:

  1. Draw your primary chart.
  2. Clone the x- and y- axes using twin.
  3. Set the new axes to be a scatter plot.
  4. Draw the points on the new axes.

That's it.

Let's look at an example:

from deephaven import time_table
from deephaven.plot.figure import Figure
from deephaven.plot import PlotStyle
from deephaven.plot import Color, Colors
from deephaven.plot import font_family_names, Font, FontStyle, Shape


data = time_table('PT00:00:01') \
.update(["Open = 10*sin(0.2*ii) + 2*random()","High = Open + 1", "Low = Open - 1", "Close = Open + 0.5"])

points = data \
.where("i%5 = 0") \
.view(["Timestamp", "Type= i%3==0 ? `Sell` : `Buy`", "Point = i%3==0 ? High+1 : Low-1"])

plot = Figure() \
.figure_title("OHLC + Points")\
.plot_xy(series_name="OHLC", t=data, x="Timestamp", y_high="High", y_low="Low", y="Close") \
.twin() \
.axes(plot_style=PlotStyle.SCATTER) \
.plot_xy(series_name="Buy", t=points.where("Type=`Buy`"), x="Timestamp", y="Point") \
.plot_xy(series_name="Sell", t=points.where("Type=`Sell`"), x="Timestamp", y="Point") \
.show()

Tell us about your project or feature requests on Deephaven Community Slack.