Multiple Series
There are two ways to plot multiple series in a chart.
- Using multiple individual plotting methods chained together.
- Using the
plotBy
group of methods.
plotBy
Multiple plot methods can be used within the same query to produce a chart with multiple series. However, the plotBy methods
include an additional argument that enables users to specify the grouping column to be used to plot multiple series. This greatly simplifies and shortens the query structure:
t1 = db.t("LearnDeephaven","StockTrades")
.where("Date=`2017-08-25`")
t2=t1.where("USym in `PFE`,`CSCO`,`INTC`,`BAC`")
plotBySample = plotBy("Aug25", t2, "Timestamp", "Last", "USym")
.xBusinessTime()
.show()
from deephaven import Plot
t1 = db.t("LearnDeephaven", "StockTrades")\
.where("Date=`2017-08-25`")
t2 = t1.where("USym in `PFE`,`CSCO`,`INTC`,`BAC`")
plotBySample = Plot.plotBy("Aug25", t2, "Timestamp", "Last", "USym")\
.xBusinessTime()\
.show()
There are three versions of the plotBy
methods:
-
.plotBy("Series1", source, "xCol", "yCol", "groupByCol").show()
-
.catPlotBy("SeriesName", source, "CategoryCol", "ValueCol", "groupByCol").show()
-
.ohlcPlotBy("SeriesName", source, "Time", "Open", "High", "Low", "Close" "groupByCol").show()
Plotting Styles
The plotStyle
methods provide users with a convenient way to change the default output for certain plotting methods. For example, an XY series plot defaults to a line chart. However, you can easily the line chart to another style by inserting the appropriate name; e.g.,.plotStyle("stacked_area")
:
t_pb = db.t("LearnDeephaven", "EODTrades")
.where("ImportDate = `2017-11-01`", "Ticker in `GOOG`,`AMZN`,`AAPL`, `MSFT`")
.update("DateString = EODTimestamp.toDateString(TZ_NY)")
.where("inRange(DateString, `2016-11-01`, `2016-12-01`)")
plotByExampleStackedArea = plotBy("TradesByDay", t_pb, "EODTimestamp", "Volume", "Ticker")
.chartTitle("Trades Per Day By Ticker")
.xLabel("Date")
.yLabel("Volume")
.plotStyle("stacked_area")
.show()
from deephaven import Plot
t_pb = db.t("LearnDeephaven", "EODTrades").where("ImportDate = `2017-11-01`", "Ticker in `GOOG`,`AMZN`,`AAPL`, `MSFT`")\
.update("DateString = EODTimestamp.toDateString(TZ_NY)")\
.where("inRange(DateString, `2016-11-01`, `2016-12-01`)")
plotByExampleStackedArea = Plot.plotBy("TradesByDay", t_pb, "EODTimestamp", "Volume", "Ticker")\
.chartTitle("Trades Per Day By Ticker")\
.xLabel("Date")\
.yLabel("Volume")\
.plotStyle("stacked_area")\
.show()