Legacy Plotting API chart types
The Legacy plot
method may be used to create several chart types, including:
Note
For Core+ workers, see Community Core documentation for plotting.
XY Series
An XY series plot is generally used to show values over a continuum, such as time. XY Series plots can be represented as a line, a bar, an area or as a collection of points. The X axis is used to show the domain, while the Y axis shows the related values at specific points in the range.
XY Series plots can be created using data from tables, arrays and functions.
XY Series Plot using Data from a Table
When data is sourced from a table, the following syntax can be used to create an XY Series plot:
.plot("SeriesName", source, "xCol", "yCol").show()
plot
is the method used to create an XY series plot."SeriesName"
is the name (as a string) you want to use to identify the series on the plot itself.source
is the table that holds the data you want to plot."xCol"
is the name of the column of data to be used for the X value."yCol"
is the name of the column of data to be used for the Y value.show
tells Deephaven to draw the plot in the console.
The example query below will create an XY series plot that shows the price of a single security (AAPL) over time.
Note
Python users must import the appropriate module: from deephaven import Plot
or from deephaven import Plot as plt
//source the data
t1 = db.t("LearnDeephaven","StockTrades").where("Date=`2017-08-24`")
//plot the data
PlotSingle = plot("AAPL", t1.where("USym = `AAPL`"), "Timestamp", "Last")
.xBusinessTime()
.show()
from deephaven import Plot
# source the data
t1 = db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-24`")
# plot the data
PlotSingle = (
Plot.plot("AAPL", t1.where("USym = `AAPL`"), "Timestamp", "Last")
.xBusinessTime()
.show()
)
Tip
The xBusinessTime
method limits the data to actual business hours.
XY Series Plot using Data from an Array
When data is sourced from an array, the following syntax can be used to create an XY Series plot:
.plot("SeriesName", [x], [y]).show()
plot
is the method used to create an XY series plot."SeriesName"
is the name (as a string) you want to use to identify the series on the plot itself.[x]
is the array containing the data to be used for the X value.[y]
is the array containing the data to be used for the Y value.show
tells Deephaven to draw the plot in the console.
XY Series Plot using Data from a Function
When data is sourced from a function, the following syntax can be used to create an XY Series plot:
.plot("SeriesName", function).show()
plot
is the method used to create an XY series plot."SeriesName"
is the name (as a string) you want to use to identify the series on the plot itself.function
is a mathematical operation that maps one value to another. Examples of Groovy functions and their formatting follow:{x->x+100}
adds 100 to the value of x.{x->x*x}
squares the value of x.{x->1/x}
uses the inverse of x.{x->x*9/5+32}
Fahrenheit to Celsius conversion.
show
tells Deephaven to draw the plot in the console.
Special considerations when plotting from a function
If you are plotting a function in a plot by itself, consider applying a range for the function using the funcRange
or xRange
method. Otherwise, the default value ([0,1]
) will be used, which may not meet your requirements:
.plot("Function", {x->x*x} ).funcRange(0,10).show()
If the function is being plotted with other data series, the funcRange
method is not needed, and the range will be obtained from the other data series.
When using a function plot, you may also want to increase or decrease the granularity of the plot by declaring the number of points to include in the range. This is configurable using the funcNPoints
method:
.plot("Function", {x->x*x} ).funcRange(0,10).funcNPoints(55).show()
XY Series with Shared Axes
You can compare multiple series over the same period of time by creating an XY series plot with shared axes. In the following example, two series are plotted, thereby creating two line graphs on the same plot.
//source the data
t2 = db.t("LearnDeephaven","StockTrades")
.where("Date=`2017-08-24`","USym in `INTC`,`CSCO`")
//plot the data
plotSharedAxis = plot("INTC", t2.where("USym = `INTC`"), "Timestamp", "Last")
.plot("CSCO", t2.where("USym = `CSCO`"), "Timestamp", "Last")
.xBusinessTime()
.show()
from deephaven import Plot
# source the data
t2 = db.t("LearnDeephaven", "StockTrades").where(
"Date=`2017-08-24`", "USym in `INTC`,`CSCO`"
)
# plot the data
plotSharedAxis = (
Plot.plot("INTC", t2.where("USym = `INTC`"), "Timestamp", "Last")
.plot("CSCO", t2.where("USym = `CSCO`"), "Timestamp", "Last")
.xBusinessTime()
.show()
)
Subsequent series can be added to the plot by adding additional plot()
methods to the query. However, the plotBy()
method can also be used to do this.
Note
See
plotBy(./)
XY Series with Multiple X or Y Axes
When plotting multiple series in a single plot, the range of the Y axis is an important factor to watch. In the previous example, both securities had values within in a relatively narrow range (31 to 35). Therefore, any change in values was easy to visualize. However, as the range of the Y axis increases, those changes become harder to assess.
To demonstrate this, let's plot AAPL and GOOG on the same chart:
//source the data
t3 = db.t("LearnDeephaven","StockTrades").where("Date=`2017-08-24`","USym in `AAPL`,`GOOG`")
//plot the data
plotShared2 = plot("AAPL", t3.where("USym = `AAPL`"), "Timestamp", "Last")
.plot("GOOG", t3.where("USym = `GOOG`"), "Timestamp", "Last")
.xBusinessTime()
.show()
from deephaven import Plot
# source the data
t3 = db.t("LearnDeephaven", "StockTrades").where(
"Date=`2017-08-24`", "USym in `AAPL`,`GOOG`"
)
# plot the data
plotShared2 = (
Plot.plot("AAPL", t3.where("USym = `AAPL`"), "Timestamp", "Last")
.plot("GOOG", t3.where("USym = `GOOG`"), "Timestamp", "Last")
.xBusinessTime()
.show()
)
Now, the scale of the Y axis needs to cover a much wider range (from 150 to 950), which results in relatively flat lines with barely distinguishable differences in values or trend.
This issue can be easily remedied by adding a second Y axis to the plot via the twinX()
method.
twinX
The twinX()
method enables you to use one Y axis for some of the series being plotted and a second Y axis for the others, while sharing the same X axis:
PlotName = figure().plot(...).twinX().plot(...).show()
- The plot(s) for the series placed before the
twinX()
method share a common Y axis (on the left). - The plot(s) for the series listed after the
twinX()
method share a common Y axis (on the right). - All plots share the same X axis.
For example, we can create an improved chart for AAPL and GOOG together:
//source the data
t4 = db.t("LearnDeephaven","StockTrades").where("Date=`2017-08-24`","USym in `AAPL`,`GOOG`")
//plot the data
plotSharedTwinX = plot("AAPL", t4.where("USym = `AAPL`"), "Timestamp", "Last")
.twinX()
.plot("GOOG", t4.where("USym = `GOOG`"), "Timestamp", "Last")
.xBusinessTime()
.show()
from deephaven import Plot
# source the data
t4 = db.t("LearnDeephaven", "StockTrades").where(
"Date=`2017-08-24`", "USym in `AAPL`,`GOOG`"
)
# plot the data
plotSharedTwinX = (
Plot.plot("AAPL", t4.where("USym = `AAPL`"), "Timestamp", "Last")
.twinX()
.plot("GOOG", t4.where("USym = `GOOG`"), "Timestamp", "Last")
.xBusinessTime()
.show()
)
The value range for AAPL is shown on the left axis and the value range for GOOG is shown on the right axis:
twinY
The twinY()
method enables you to use one X axis for one set of the values being plotted and a second X axis for another, while sharing the same Y axis:
PlotName = figure().plot(...).twinY().plot(...).show()
- The plot(s) for the series placed before the
twinY()
method use the lower X axis. - The plot(s) for the series listed after the
twinY()
method use the upper X axis.
XY Series with Plot Styles
The XY series plot in Deephaven defaults to a line plot. However, Deephaven's plotStyle()
method can be used to format XY series plots as area charts, stacked area charts, bar charts, stacked bar charts, scatter charts and step charts.
In any of the examples below, you can simply swap out the .plotStyle()
argument with the appropriate name; e.g., ("area")
, ("stacked_area")
, ("step")
, etc.
Note
See Plot Styles
XY Series as a Stacked Area Plot
t5 = db.t("LearnDeephaven", "EODTrades")
.where("ImportDate = `2017-11-01`", "Ticker in `AAPL`, `MSFT`")
.update("DateString = EODTimestamp.toDateString(TZ_NY)")
.where("inRange(DateString, `2016-11-01`, `2016-12-01`)")
plotXYStackedArea = plot("AAPL", t5.where("Ticker = `AAPL`"), "EODTimestamp", "Volume")
.plot("MSFT", t5.where("Ticker = `MSFT`"), "EODTimestamp", "Volume")
.chartTitle("Trades Per Day By Ticker")
.xLabel("Date")
.yLabel("Volume")
.plotStyle("stacked_area")
.show()
from deephaven import Plot
t5 = (
db.t("LearnDeephaven", "EODTrades")
.where("ImportDate = `2017-11-01`", "Ticker in `AAPL`, `MSFT`")
.update("DateString = EODTimestamp.toDateString(TZ_NY)")
.where("inRange(DateString, `2016-11-01`, `2016-12-01`)")
)
plotXYStackedArea = (
Plot.plot("AAPL", t5.where("Ticker = `AAPL`"), "EODTimestamp", "Volume")
.plot("MSFT", t5.where("Ticker = `MSFT`"), "EODTimestamp", "Volume")
.chartTitle("Trades Per Day By Ticker")
.xLabel("Date")
.yLabel("Volume")
.plotStyle("stacked_area")
.show()
)
XY Series as a Scatter Plot
t6 = db.t("LearnDeephaven", "StockTrades")
.where("Date = `2017-08-25`", "USym in `AAPL`, `GOOG`, `MSFT`")
.update("TimeBin = lowerBin(Timestamp, SECOND)")
.firstBy("TimeBin")
.where("TimeBin > '2017-08-25T10:00 NY' && TimeBin < '2017-08-25T11:00 NY'")
plotXYScatter = plot("AAPL", t6.where("USym = `AAPL`"), "Timestamp", "Last")
.plotStyle("scatter")
.pointSize(0.5)
.pointColor(colorRGB(0,0,255,50))
.pointShape("circle")
.twinX()
.plot("MSFT", t6.where("USym = `MSFT`"), "Timestamp", "Last")
.plotStyle("scatter")
.pointSize(0.8)
.pointColor(colorRGB(255,0,0,100))
.pointShape("up_triangle")
.chartTitle("AAPL vs MSFT (10-11am ET)")
.show()
from deephaven import Plot
t6 = (
db.t("LearnDeephaven", "StockTrades")
.where("Date = `2017-08-25`", "USym in `AAPL`, `GOOG`, `MSFT`")
.update("TimeBin = lowerBin(Timestamp, SECOND)")
.firstBy("TimeBin")
.where("TimeBin > '2017-08-25T10:00 NY' && TimeBin < '2017-08-25T11:00 NY'")
)
plotXYScatter = (
Plot.plot("AAPL", t6.where("USym = `AAPL`"), "Timestamp", "Last")
.plotStyle("scatter")
.pointSize(0.5)
.pointColor(Plot.colorRGB(0, 0, 255, 50))
.pointShape("circle")
.twinX()
.plot("MSFT", t6.where("USym = `MSFT`"), "Timestamp", "Last")
.plotStyle("scatter")
.pointSize(0.8)
.pointColor(Plot.colorRGB(255, 0, 0, 100))
.pointShape("up_triangle")
.chartTitle("AAPL vs MSFT (10-11am ET)")
.show()
)
XY Series as a Step Plot
t7 = db.t("LearnDeephaven","StockTrades")
.where("Date=`2017-08-24`","USym=`GOOG`")
.updateView("TimeBin=upperBin(Timestamp, 30 * MINUTE)")
.where("isBusinessTime(TimeBin)")
plotXYStep = plot("GOOG", t7.where("USym = `GOOG`")
.lastBy("TimeBin"), "TimeBin", "Last")
.plotStyle("Step")
.lineStyle(lineStyle(3))
.show()
from deephaven import Plot
t7 = (
db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-24`", "USym=`GOOG`")
.updateView("TimeBin=upperBin(Timestamp, 30 * MINUTE)")
.where("isBusinessTime(TimeBin)")
)
plotXYStep = (
Plot.plot("GOOG", t7.where("USym = `GOOG`").lastBy("TimeBin"), "TimeBin", "Last")
.plotStyle("Step")
.lineStyle(Plot.lineStyle(3))
.show()
)
Category
Category plots display data values from different discrete categories. They can be created using data from tables and arrays.
Category Plot using Data from a Table
When data is sourced from a table, the following syntax can be used to create a category:
.catPlot("SeriesName", source, "CategoryCol", "ValueCol").show()
catPlot
is the method used to create a category plot."SeriesName"
is the name (string) you want to use to identify the series on the plot itself.source
is the table that holds the data you want to plot."CategoryCol"
is the name of the column (as a string) to be used for the categories."ValueCol"
is the name of the column (as a string) to be used for the values.show
tells Deephaven to draw the plot in the console.
//source the data
t1c = db.t("LearnDeephaven", "StockTrades")
.where("Date > `2017-08-20`", "USym = `MSFT`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
totalSharesByUSym = t1c.view("Date", "USym", "SharesTraded=Size")
.sumBy("Date", "USym")
//build the plot
categoryPlot = catPlot("MSFT", totalSharesByUSym.where("USym = `MSFT`"), "Date", "SharesTraded")
.chartTitle("Shares Traded")
.show()
from deephaven import Plot
# source the data
t1c = (
db.t("LearnDeephaven", "StockTrades")
.where("Date > `2017-08-20`", "USym = `MSFT`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
)
totalSharesByUSym = t1c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
# build the plot
categoryPlot = (
Plot.catPlot(
"MSFT", totalSharesByUSym.where("USym = `MSFT`"), "Date", "SharesTraded"
)
.chartTitle("Shares Traded")
.show()
)
Category Plot using Data from Arrays
When data is sourced from a array, the following syntax can be used to create a category:
.catPlot("SeriesName", [category], [values]).show()
catPlot
is the method used to create a category plot."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.[category]
is the array containing the data to be used for the X values.[values]
is the array containing the data to be used for the Y values.show
tells Deephaven to draw the plot in the console.
Categories with Shared Axes
You can also compare multiple categories over the same period of time by creating a category plot with shared axes. In the following example, a second category plot has been added to the previous example, thereby creating bar graphs on the same chart:
t2c = db.t("LearnDeephaven", "StockTrades")
.where("Date > `2017-08-20`", "USym in `AAPL`, `MSFT`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
totalSharesByUSym2 = t2c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
categoryPlot2 = catPlot("MSFT", totalSharesByUSym2.where("USym = `MSFT`"), "Date", "SharesTraded")
.catPlot("AAPL", totalSharesByUSym2.where("USym = `AAPL`"), "Date", "SharesTraded")
.chartTitle("Shares Traded")
.show()
from deephaven import Plot
t2c = (
db.t("LearnDeephaven", "StockTrades")
.where("Date > `2017-08-20`", "USym in `AAPL`, `MSFT`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
)
totalSharesByUSym2 = t2c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
categoryPlot2 = (
Plot.catPlot(
"MSFT", totalSharesByUSym2.where("USym = `MSFT`"), "Date", "SharesTraded"
)
.catPlot("AAPL", totalSharesByUSym2.where("USym = `AAPL`"), "Date", "SharesTraded")
.chartTitle("Shares Traded")
.show()
)
Subsequent categories can be added to the chart by adding additional catPlot() methods to the query. However, the plotBy()
method can also be used to do this.
Note
See
plotBy(./)
Category charts with Plot Styles
By default, values are presented as vertical bars. However, by using Deephaven's plotStyle()
method, the data can be represented as a bar, a stacked bar, a line, an area or a stacked area.
In any of the examples below, you can simply swap out the .plotStyle()
argument with the appropriate name; e.g., ("Area")
, ("stacked_area")
, etc.
Note
See Plot Styles
Category Plot with Stacked Bar
t2c = db.t("LearnDeephaven", "StockTrades")
.where("Date >`2017-08-20`", "USym in `AAPL`, `MSFT`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
totalSharesByUSym2 = t2c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
categoryPlotStacked = catPlot("MSFT", totalSharesByUSym2.where("USym = `MSFT`"), "Date", "SharesTraded")
.catPlot("AAPL", totalSharesByUSym2.where("USym = `AAPL`"), "Date", "SharesTraded")
.plotStyle("stacked_bar")
.chartTitle("Shares Traded")
.show()
from deephaven import Plot
t2c = (
db.t("LearnDeephaven", "StockTrades")
.where("Date >`2017-08-20`", "USym in `AAPL`, `MSFT`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
)
totalSharesByUSym2 = t2c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
categoryPlotStacked = (
Plot.catPlot(
"MSFT", totalSharesByUSym2.where("USym = `MSFT`"), "Date", "SharesTraded"
)
.catPlot("AAPL", totalSharesByUSym2.where("USym = `AAPL`"), "Date", "SharesTraded")
.plotStyle("stacked_bar")
.chartTitle("Shares Traded")
.show()
)
Multiple Sets of Stacked Category Plots
Note
This feature is currently available in Deephaven Classic, and will be coming to the web soon.
Multiple sets of stacked category plots can be created by assigning each category to a group and then applying a plot style:
t3c = db.t("LearnDeephaven", "StockTrades")
.where("Date > `2017-08-20`", "USym in `AAPL`, `MSFT`, `IBM`, `CSCO`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
totalSharesByUSym3 = t3c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
multiStackCatPlot = catPlot("MSFT", totalSharesByUSym3.where("USym = `MSFT`"), "Date", "SharesTraded")
.group(1)
.catPlot("AAPL", totalSharesByUSym3.where("USym = `AAPL`"), "Date", "SharesTraded")
.group(1)
//the two series above are assigned to group 1
.catPlot("IBM", totalSharesByUSym3.where("USym = `IBM`"), "Date", "SharesTraded")
.group(2)
.catPlot("CSCO", totalSharesByUSym3.where("USym = `CSCO`"), "Date", "SharesTraded")
.group(2)
//the two series above are assigned to group 2
.plotStyle("stacked_bar")
.chartTitle("Shares Traded")
.show()
from deephaven import Plot
t3c = (
db.t("LearnDeephaven", "StockTrades")
.where("Date > `2017-08-20`", "USym in `AAPL`, `MSFT`, `IBM`, `CSCO`")
.view("Date", "USym", "Last", "Size", "ExchangeTimestamp")
)
totalSharesByUSym3 = t3c.view("Date", "USym", "SharesTraded=Size").sumBy("Date", "USym")
multiStackCatPlot = (
Plot.catPlot(
"MSFT", totalSharesByUSym3.where("USym = `MSFT`"), "Date", "SharesTraded"
)
.group(1)
.catPlot("AAPL", totalSharesByUSym3.where("USym = `AAPL`"), "Date", "SharesTraded")
.group(1)
.catPlot("IBM", totalSharesByUSym3.where("USym = `IBM`"), "Date", "SharesTraded")
.group(2)
.catPlot("CSCO", totalSharesByUSym3.where("USym = `CSCO`"), "Date", "SharesTraded")
.group(2)
.plotStyle("stacked_bar")
.chartTitle("Shares Traded")
.show()
)
Category Histogram
The category histogram plot is used to show how frequently a set of discrete values (categories) occur. They can be plotted using data from tables or arrays.
Category Histogram Plot using Data from a Table
When data is sourced from a table, the following syntax can be used:
.catHistPlot("seriesName", source, "ValueCol").show()
catHistPlot
is the method used to create a category histogram."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.source
is the table that holds the data you want to plot."ValueCol"
is the name of the column (as a string) containing the discrete values.show
tells Deephaven to draw the plot in the console.
tHist = db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-25`")
.view("Sym", "Last", "Size", "ExchangeTimestamp")
catHistTradesBySym = catHistPlot("Number of Trades", tHist, "Sym")
.chartTitle("Trades per Symbol")
.show()
from deephaven import Plot
tHist = (
db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-25`")
.view("Sym", "Last", "Size", "ExchangeTimestamp")
)
catHistTradesBySym = (
Plot.catHistPlot("Number of Trades", tHist, "Sym")
.chartTitle("Trades per Symbol")
.show()
)
This query plots the histogram as follows:
catHistTradesBySym
is the name of the variable that will hold the plot.catHistPlot
is the method."Number of Trades"
is the name of the series to use in the plot.trades
is the table from which our data is being pulled.Sym
is the name of the column containing the discrete values.chartTitle("Trades per Symbol")
adds a chart title to the plot.
Category Histogram Plot using Data from an Array
When data is sourced from an array, the following syntax can be used:
.catHistPlot("SeriesName", [Values]).show()
catHistPlot
is the method used to create a category histogram."SeriesName"
is the name (as a string) you want to use to identify the series on the plot itself.[Values]
is the array containing the discrete values.show
tells Deephaven to draw the plot in the console.
Histogram
The histogram is used to show how frequently different data values occur. The data is divided into logical intervals (or bins) , which are then aggregated and charted with vertical bars. Unlike bar charts (category plots), bars in histograms do not have spaces between them unless there is a gap in the data. Histograms can be plotted using data from tables or arrays.
Histogram Plot using Data from a Table
When data is sourced from a table, the following syntax can be used:
.histPlot("seriesName", source, "ValueCol", nbins).show()
histPlot
is the method used to create a histogram."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.source
is the table that holds the data you want to plot."ValueCol"
is the name of the column (as a string) of data to be used for the X values.nbins
is the number of intervals to use in the chart.show
tells Deephaven to draw the plot in the console.
tHist = db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-25`")
.view("Sym", "Last", "Size", "ExchangeTimestamp")
plotPriceIntervals = histPlot("AAPL", tHist.where("Sym=`AAPL`"), "Last", 10)
.chartTitle("Price Intervals")
.show()
from deephaven import Plot
tHist = (
db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-25`")
.view("Sym", "Last", "Size", "ExchangeTimestamp")
)
plotPriceIntervals = (
Plot.histPlot("AAPL", tHist.where("Sym=`AAPL`"), "Last", 10)
.chartTitle("Price Intervals")
.show()
)
This query plots the histogram as follows:
plotPriceIntervals
is the name of the variable that will hold the chart.histPlot
is the method."AAPL"
is the name of the series to use in the chart.trades.where("Sym=`AAPL`")
is the source data filtered to AAPL.Last
is table column that contains the values we want to plot, and10
is the number of intervals we want to use to divide up the sales.
The histPlot
method assumes you want to plot the entire range of values in the dataset. However, you can also set the minimum and maximum values of the range using rangeMin
and rangeMax
respectively:
.histPlot("seriesName", source, "ValueCol", rangeMin, rangeMax, nbins).show()
histPlot
is the method used to create a histogram."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.source
is the table that holds the data you want to plot."ValueCol"
is the name of the column (as a string) of data to be used for the X values.rangeMin
is the minimum value (as a double) of the range to be included.rangeMax
is the maximum value (as a double) of the range to be included.nbins
is the number of intervals to use in the chart.show
tells Deephaven to draw the plot in the console.
Histogram Plot using Data from an Array
When data is sourced from an array, the following syntax can be used:
.histPlot("SeriesName", [x], nbins).show()
histPlot
is the method used to create a histogram."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.[x]
is the array containing the data to be used for the X values.nbins
is the number of intervals to use in the chart.show
tells Deephaven to draw the plot in the console.
The histPlot
method assumes you want to plot the entire range of values in the dataset. However, you can also set the minimum and maximum values of the range using rangeMin
and rangeMax
respectively:
.histPlot("SeriesName", [x], rangeMin, rangeMax, nbins).show()
histPlot
is the method used to create a histogram."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.[x]
is the array containing the data to be used for the X values.rangeMin
is the minimum value (as a double) of the range to be included.rangeMax
is the maximum value (as a double) of the range to be included.nbins
is the number of the intervals to use in the chart.show
tells Deephaven to draw the plot in the console.
OHLC
The Open, High, Low and Close (OHLC) plot typically shows four prices of a security or commodity per time slice: the open and close of the time slice, and the highest and lowest values reached during the time slice.
This plotting method requires a dataset that includes one column containing the values for the X axis (time), and one column for each of the corresponding four values (open, high, low, close). Open, High, Low and Close Plots can be created using data from tables or arrays.
OHLC Plot using Data from a Table
When data is sourced from a table, the following syntax can be used:
.ohlcPlot("SeriesName", source, "Time", "Open", "High", "Low", "Close").show()
ohlcPlot
is the method used to create an OHLC chart."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.source
is the table that holds the data you want to plot."Time"
is the name (as a string) of the column to be used for the X axis."Open"
is the name of the column (as a string) holding the opening price."High"
is the name of the column (as a string) holding the highest price."Low"
is the name of the column (as a string) holding the lowest price."Close"
is the name of the column (as a string) holding the closing price.show
tells Deephaven to draw the plot in the console.
tOHLC = db.t("LearnDeephaven","EODTrades")
.where("Ticker=`AAPL`", "ImportDate=`2017-11-01`", "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")
plotOHLC = ohlcPlot("AAPL", tOHLC, "EODTimestamp", "Open", "High", "Low", "Close")
.xBusinessTime()
.lineStyle(lineStyle(2))
.chartTitle("AAPL OHLC - June-July 2017")
.show()
from deephaven import Plot
tOHLC = db.t("LearnDeephaven", "EODTrades").where(
"Ticker=`AAPL`",
"ImportDate=`2017-11-01`",
"inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')",
)
plotOHLC = (
Plot.ohlcPlot("AAPL", tOHLC, "EODTimestamp", "Open", "High", "Low", "Close")
.xBusinessTime()
.lineStyle(Plot.lineStyle(2))
.chartTitle("AAPL OHLC - June-July 2017")
.show()
)
This query plots the OHLC chart as follows:
plotOHLC
is the name of the variable that will hold the chart.ohlcPlot
is the method."AAPL"
is the name of the series to be used in the chart.tOHLC
is the table from which our data is being pulled.EODTimestamp
is the name of the column to be used for the X axis."Open"
,"High"
,"Low"
, and"Close"
, are the names of the columns containing the four respective data points to be plotted on the Y axis.xBusinessTime()
limits the date to business days only.lineStyle()
andchartTitle()
provide component formatting to the table.2
refers to line width.
OHLC Plot using Data from an Array
When data is sourced from an array, the following syntax can be used:
.ohlcPlot("SeriesName",[Time], [Open], [High], [Low], [Close]).show()
ohlcPlot
is the method used to create an OHLC chart."SeriesName"
is the name (as a string) you want to use to identify the series on the chart itself.[Time]
is the array containing the data to be used for the X axis.[Open]
is the array containing the data to be used for the opening price.[High]
is the array containing the data to be used for the highest price.[Low]
is the array containing the data to be used for the lowest price.[Close]
is the array containing the data to be used for the closing price.show
tells Deephaven to draw the plot in the console.
OHLC Plots with Shared Axes
Just like XY series plots, the Open, High, Low and Close plot can also be used to present multiple series on the same chart, including the use of multiple X or Y axes. An example of this follows:
t2OHLC = db.t("LearnDeephaven","EODTrades")
.where("Ticker in `AAPL`, `MSFT`", "ImportDate=`2017-11-01`", "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")
plotOHLC2 = ohlcPlot("AAPL", t2OHLC.where("Ticker = `AAPL`"),"EODTimestamp","Open","High","Low","Close")
.lineStyle(lineStyle(2))
.twinX()
.ohlcPlot("MSFT", t2OHLC.where("Ticker = `MSFT`"),"EODTimestamp","Open","High","Low","Close")
.xBusinessTime()
.lineStyle(lineStyle(2))
.chartTitle("AAPL vs MSFT OHLC - June-July 2017")
.show()
from deephaven import Plot
t2OHLC = db.t("LearnDeephaven", "EODTrades").where(
"Ticker in `AAPL`, `MSFT`",
"ImportDate=`2017-11-01`",
"inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')",
)
plotOHLC2 = (
Plot.ohlcPlot(
"AAPL",
t2OHLC.where("Ticker = `AAPL`"),
"EODTimestamp",
"Open",
"High",
"Low",
"Close",
)
.lineStyle(Plot.lineStyle(2))
.twinX()
.ohlcPlot(
"MSFT",
t2OHLC.where("Ticker = `MSFT`"),
"EODTimestamp",
"Open",
"High",
"Low",
"Close",
)
.xBusinessTime()
.lineStyle(Plot.lineStyle(2))
.chartTitle("AAPL vs MSFT OHLC - June-July 2017")
.show()
)
This query plots the OHLC chart as follows:
plotOHLC2
is the name of the variable that will hold the chart.ohlcPlot
plots the first series."AAPL"
is the name of the first series to be used in the chart.t2OHLC
is the table from which the data is being pulled.where("Ticker=`AAPL`")
filters the table to only the AAPL Ticker.EODTimestamp
is the name of the column to be used for the X axis."Open"
,"High"
, "Low"
, and"Close"
, are the names of the columns containing the four respective data points to be plotted on the Y axis.- The
lineStyle()
method needs to be assigned to each series, so this reference only applies to the first series.
twinX
is used to show different Y axes.ohlcPlot
plots the second series."MSFT"
is the name of the second series to be used in the chart.t2OHLC
is the table from which the data is being pulled.where("Ticker=`MSFT`")
filters the table to only the MSFT Ticker.EODTimestamp
is the name of the column to be used for the X axis."Open"
,"High"
,"Low"
, and"Close"
, are the names of the columns containing the four respective data points to be plotted on the Y axis.lineStyle()
applies only to the second series.
xBusinessTime()
limits the date to business days only.chartTitle()
provides the title for the chart.
In this plot, the opening, high, low and closing price of AAPL and MSFT are plotted. The twinX()
method is used to show the value scale for AAPL on the left Y axis and the value scale for MSFT on the right Y axis.
Pie
The pie plot shows data as sections of a circle to represent the relative proportion for each of the categories that make up the entire dataset being plotted.
Pies plots can be created using data from tables or arrays.
Pie Plot using Data from a Table
When data is sourced from a table, the following syntax can be used to create a pie plot:
.piePlot("SeriesName", source, "CategoryCol", "ValueCol").show()
piePlot
is the method used to create a pie plot."SeriesName"
is the name (as a string) you want to use to identify the series on the plot itself.source
is the table that holds the data you want to plot."CategoryCol"
is the name of the column (as a string) to be used for the categories."ValueCol"
is the name of the column (as a string) to be used for the values.show
tells Deephaven to draw the plot in the console.
tPie = db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-25`")
.view("Sym", "Last", "Size", "ExchangeTimestamp")
totalShares = tPie.view("Sym", "SharesTraded=Size").sumBy("Sym")
pieChart = piePlot("Shares Traded", totalShares, "Sym", "SharesTraded")
.chartTitle("Total Shares")
.show()
from deephaven import Plot
tPie = (
db.t("LearnDeephaven", "StockTrades")
.where("Date=`2017-08-25`")
.view("Sym", "Last", "Size", "ExchangeTimestamp")
)
totalShares = tPie.view("Sym", "SharesTraded=Size").sumBy("Sym")
pieChart = (
Plot.piePlot("Shares Traded", totalShares, "Sym", "SharesTraded")
.chartTitle("Total Shares")
.show()
)
Pie Plot using Data from an Array
When data is sourced from an array, the following syntax can be used:
.piePlot("SeriesName", [category], [values]").show()
piePlot
is the method used to create a pie chart."SeriesName"
is the name (as a string) you want to use to identify the series on the chart.[category]
is the array containing the data to be used for the X values.[values]
is the array containing the data to be used for the Y values.show
tells Deephaven to draw the plot in the console.