def testMultiSeries(self): """ Test suite for methods inherited from MultiSeries - bah... """ # NB: the error message: # java.lang.UnsupportedOperationException: Series type does not support this method. # seriesType=class io.deephaven.db.plot.datasets.xy.XYDataSeriesTableArray # method='@Override public FigureImpl pointsVisible( java.lang.Boolean visible, java.lang.Object... keys )' # TODO: seriesNamingFunction(*args)?,pointColorByY(func, *keys)? # TODO: a ton of other call signatures for basically XYDataSeriesMethods figure = Plot.plot("Microsoft", self.table.where("Sym=`MSFT`"), "timestamp", "price")\ .plot("Apple", self.table.where("Sym=`AAPL`"), "timestamp", "price") with self.subTest(msg="gradientVisible(boolean, *keys)"): figure = figure.gradientVisible(True, "Microsoft") with self.subTest(msg="lineColor(Paint/int/string, *keys)"): figure = figure.lineColor("RED", "Apple") with self.subTest(msg="lineStyle(LineStyle, *keys)"): figure = figure.lineStyle(Plot.lineStyle(4.0, 4.0), "Microsoft", "Apple") with self.subTest(msg="linesVisible(boolean, *keys)"): figure = figure.linesVisible(True, "Microsoft", "Apple") with self.subTest(msg="pointColor(Paint/int/string, *keys)"): figure = figure.pointColor("BLUE", "Microsoft", "Apple") with self.subTest(msg="pointLabel(object, *keys)"): figure = figure.pointLabel("label", "Microsoft", "Apple") with self.subTest(msg="pointLabelFormat(string, *keys)"): figure = figure.pointLabelFormat("{0}: ({1}, {2})", "Microsoft", "Apple") with self.subTest(msg="pointShape(string, *keys)"): figure = figure.pointShape("SQUARE", "Microsoft", "Apple") with self.subTest(msg="pointSize(double, *keys)"): figure = figure.pointSize(2.0, "Microsoft", "Apple") with self.subTest(msg="pointsVisible(boolean, *keys)"): figure = figure.pointsVisible(True, "Microsoft", "Apple") with self.subTest(msg="seriesColor(Paint/int/string, *keys)"): figure = figure.seriesColor(Plot.colorRGB(255, 0, 0), "Microsoft", "Apple") with self.subTest(msg="tool tips"): figure = figure.toolTipPattern("###,###.00", "Apple")\ .xToolTipPattern("###,###.00", "Apple")\ .yToolTipPattern("###,###.00", "Apple") with self.subTest(msg="group(int, *keys)"): figure = figure.group(0, "Microsoft", "Apple") del figure
def testPlot(self): """ plot method calls - possibly expand over time """ # perform basic Plot.plot(name, x, y), where x, y span every pairwise choice from the self.arrays dictionary figure = None typs = sorted(self.arrays.keys()) for i, xtyp in enumerate(typs): xarray = self.arrays[xtyp] for j, ytyp in enumerate(typs): yarray = self.arrays[ytyp] with self.subTest(msg="plot({}, {})".format(xtyp, ytyp)): series_name = '{}_{}'.format(xtyp, ytyp) figure = Plot.plot(series_name, xarray, yarray).show() del figure
def testDataSeriesMethods(self): """ Test suite for methods inherited from DataSeries """ # TODO: pointColorByY(SerializableFunction)?, pointColorByY(Closure)? figure = Plot.plot("Microsoft", self.table.where("Sym=`MSFT`"), "timestamp", "price") with self.subTest(msg="linesVisible(boolean)"): figure = figure.linesVisible(True) with self.subTest(msg="lineColor(Paint)"): figure = figure.lineColor(Plot.colorRGB(0.2, 1.0, 0.2)) with self.subTest(msg="lineStyle(LineStyle)"): figure = figure.lineStyle(Plot.lineStyle(4, 4)) with self.subTest(msg="pointsVisible(boolean)"): figure = figure.pointsVisible(True) with self.subTest(msg="pointSize(double)"): figure = figure.pointSize(2.0) with self.subTest(msg="pointLabel(object)"): figure = figure.pointLabel("label") with self.subTest(msg="pointLabelFormat(string)"): figure = figure.pointLabelFormat("{0}: ({1}, {2})") with self.subTest(msg="pointShape(string)"): figure = figure.pointShape("CIRCLE") with self.subTest(msg="seriesColor(Paint)"): figure = figure.seriesColor(Plot.colorRGB(0.1, 0.1, 0.1)) with self.subTest(msg="pointColor(Paint)"): figure = figure.pointColor(Plot.colorRGB(1.0, 0.0, 0.0)) with self.subTest(msg="gradientVisible(boolean)"): figure.gradientVisible(False) with self.subTest(msg="toolTipPattern(string)"): figure = figure.toolTipPattern("###,###.00") with self.subTest(msg="xToolTipPattern(string)"): figure = figure.xToolTipPattern("###,###.00") with self.subTest(msg="yToolTipPattern(string)"): figure = figure.yToolTipPattern("###,###.00") del figure
# note that we are constraining the data to NYSE business time import deephaven.Calendars as Calendars cal = Calendars.calendar("USNYSE") trades = db.t("LearnIris", "StockTrades").where("Date=`2017-08-25`") trades = trades.where("cal.isBusinessTime(ExchangeTimestamp)") # ************* XY SERIES PLOTTING ************* # XY SERIES - SINGLE SERIES t1 = db.t("LearnDeephaven", "StockTrades")\ .where("Date=`2017-08-24`", "USym=`AAPL`") PlotSingle = Plot.plot("AAPL", t1.where("USym = `AAPL`"), "Timestamp", "Last")\ .xBusinessTime()\ .show() # XY SERIES - MULTIPLE SERIES t2 = db.t("LearnDeephaven", "StockTrades")\ .where("Date=`2017-08-24`", "USym in `INTC`,`CSCO`") plotSharedAxis = Plot.plot("INTC", t2.where("USym = `INTC`"), "Timestamp", "Last")\ .plot("CSCO", t2.where("USym = `CSCO`"), "Timestamp", "Last")\ .xBusinessTime()\ .show() # XY SERIES - MULTIPLE SERIES WITH TWINX t3 = db.t("LearnDeephaven","StockTrades")\
import deephaven.TableTools as tt import deephaven.Plot as plt t = tt.emptyTable(50)\ .update("X = i + 5", "XLow = X -1", "XHigh = X + 1", "Y = Math.random() * 5", "YLow = Y - 1", "YHigh = Y + 1", "USym = i % 2 == 0 ? `AAPL` : `MSFT`") p = plt.plot("S1", t, "X", "Y").lineColor("black").show() p2 = plt.plot("S1", t, "X", "Y").plotStyle("bar").gradientVisible(True).show() p3 = plt.plot( "S1", t, "X", "Y").plotStyle("scatter").pointColor("black").pointSize(2).show() p4 = plt.plot("S1", t, "X", "Y").plotStyle("area").seriesColor("red").show() p4 = plt.plot3d("S1", t, "X", "X", "Y").show() pBy = plt.plotBy("S1", t, "X", "Y", "USym").show() pBy = plt.plot3dBy("S1", t, "X", "X", "Y", "USym").show() cp = plt.catPlot("S1", t, "X", "Y").lineColor("black").show() cp2 = plt.catPlot("S1", t, "X", "Y").plotStyle("bar").gradientVisible(True).show() cp3 = plt.catPlot( "S1", t, "X", "Y").plotStyle("scatter").pointColor("black").pointSize(2).show() cp4 = plt.catPlot("S1", t, "X", "Y").plotStyle("area").seriesColor("red").show() cp = plt.catPlot3d("S1", t, "X", "X", "Y").show() cpBy = plt.catPlotBy("S1", t, "X", "Y", "USym").show()
# generate shared tables trades = db.t("LearnDeephaven", "StockTrades")\ .where("Date=`2017-08-25`")\ .view("Sym", "Last", "Size", "ExchangeTimestamp") # note that we are constraining the data to NYSE business time import deephaven.Calendars as Calendars cal = Calendars.calendar("USNYSE") trades = trades.where("cal.isBusinessTime(ExchangeTimestamp)") totalShares = trades.view("Sym", "SharesTraded=Size").sumBy("Sym") summaries = db.t("LearnDeephaven", "EODTrades").where("ImportDate=`2017-11-01`") # XY Series timePlot = Plot.plot("Microsoft", trades.where("Sym=`MSFT`"), "ExchangeTimestamp", "Last")\ .show() multiSeries = Plot.plot("Microsoft", trades.where("Sym=`MSFT`"), "ExchangeTimestamp", "Last")\ .twinX()\ .plot("Apple", trades.where("Sym=`AAPL`"), "ExchangeTimestamp", "Last")\ .chartTitle("Price Over Time")\ .show() # Category categoryPlot = Plot.catPlot("Shares Traded", totalShares, "Sym", "SharesTraded")\ .chartTitle("Total Shares")\ .show() # Pie pieChart = Plot.piePlot("Shares Traded", totalShares, "Sym", "SharesTraded")\ .chartTitle("Total Shares")\