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:
- Draw your primary chart.
- Clone the x- and y- axes using
twin
. - Set the new axes to be a scatter plot.
- 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.