Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when plotting xy plot over OHLC plot #2094

Closed
mofojed opened this issue Mar 11, 2022 · 5 comments · Fixed by #2988
Closed

Error when plotting xy plot over OHLC plot #2094

mofojed opened this issue Mar 11, 2022 · 5 comments · Fixed by #2988
Assignees
Labels
bug Something isn't working plotting triage
Milestone

Comments

@mofojed
Copy link
Member

mofojed commented Mar 11, 2022

Description

Try and create a plot with an OHLC plot and an XY plot

Steps to reproduce

  1. Run the following command
from deephaven import read_csv, Aggregation as agg, as_list
from deephaven import Plot

cryptoTrades = read_csv("https://media.githubusercontent.com/media/deephaven/examples/main/CryptoCurrencyHistory/CryptoTrades_20210922.csv")

agg_list = as_list([
    agg.AggLast("CloseTime = Timestamp"),\
    agg.AggFirst("OpenTime = Timestamp"),\
    agg.AggMax("High = Price"),\
    agg.AggMin("Low = Price"),
])

btcBin = cryptoTrades.where("Instrument=`BTC/USD`").update("TimestampBin = lowerBin(Timestamp, MINUTE)")
tOHLC = btcBin.aggBy(agg_list, "TimestampBin").\
 join(btcBin,"CloseTime = Timestamp","Close = Price").\
 join(btcBin,"OpenTime = Timestamp","Open = Price")

plotOHLC = Plot.ohlcPlot("BTC", tOHLC, "TimestampBin", "Open", "High", "Low", "Close")\
   .chartTitle("BTC OHLC - Aug 22 2021")\
   .twinX()\
   .plot("Open", tOHLC, "TimestampBin", "Open")\
   .show()

Expected results

  1. Plot should appear with OHLC and a line plot overtop

Actual results

  1. An error is spit out
r-Scheduler-Serial-1 | i.d.s.s.SessionState      | Internal Error '36a55d0b-3500-49a7-81e2-ef10cd95262e' java.lang.RuntimeException: Error in Python interpreter:
Type: <class 'RuntimeError'>
Value: io.deephaven.plot.errors.PlotUnsupportedOperationException: Plot Information: Chart: BTC OHLC - Aug 22 2021. Attempting to create inconsistent plot types: OHLC, XY
	at io.deephaven.plot.ChartImpl.setChartType(ChartImpl.java:167)
	at io.deephaven.plot.AxesImpl.configureXYPlot(AxesImpl.java:225)
	at io.deephaven.plot.AxesImpl.plot(AxesImpl.java:1235)
	at io.deephaven.plot.AxesImpl.plot(AxesImpl.java:1276)
	at io.deephaven.plot.FigureImpl.plot(FigureImpl.java:2593)
	at io.deephaven.plot.FigureImpl.plot(FigureImpl.java:52)
	at org.jpy.PyLib.executeCode(Native Method)
	at org.jpy.PyObject.executeCode(PyObject.java:138)
	at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:56)
	at io.deephaven.engine.util.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:190)
	at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:46)
	at io.deephaven.engine.util.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:189)
	at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:147)
	at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:71)
	at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:85)
	at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:219)
	at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1299)
	at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:847)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:143)
	at java.base/java.lang.Thread.run(Thread.java:829)

Line: 3601
Namespace: plot
File: /opt/deephaven-venv/lib/python3.7/site-packages/deephaven/Plot/figure_wrapper.py
Traceback (most recent call last):
  File "<string>", line 21, in <module>
  File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven/Plot/figure_wrapper.py", line 106, in _convertArguments
  File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven/Plot/figure_wrapper.py", line 3601, in plot

        at org.jpy.PyLib.executeCode(PyLib.java:-2)
        at org.jpy.PyObject.executeCode(PyObject.java:138)
        at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:56)
        at io.deephaven.engine.util.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:190)
        at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:46)
        at io.deephaven.engine.util.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:189)
        at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:147)
        at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:71)
        at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:85)
        at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:219)
        at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1299)
        at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:847)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:143)
        at java.lang.Thread.run(Thread.java:829)
@mofojed mofojed added bug Something isn't working triage labels Mar 11, 2022
@niloc132 niloc132 self-assigned this Sep 12, 2022
@niloc132 niloc132 added this to the Sept 2022 milestone Sep 12, 2022
@chipkent
Copy link
Member

I just hit this problem when trying to do this for a user:

from deephaven import time_table, empty_table
from deephaven.plot import Figure

t = time_table("00:00:01").update(["H=1.1*ii", "L=0.9*ii", "O=1.01*ii", "C=0.99*i", "Signal=sin(0.11*ii)"])

f = Figure() \
    .plot_ohlc("OHLC", t=t, x="Timestamp", open="O", high="H", low="L", close="C") \
    .x_twin() \
    .plot_xy("Signal", t=t, x="Timestamp", y="Signal") \
    .show()

@hhashim1
Copy link

The below code lets me graph ohlc and xy together


import jpy
figure = jpy.get_type("io.deephaven.plot.PlottingConvenience").figure

option_symbol = 'O:TSLA220902P00273330'

figure = Figure(figure(7,1))
bar_chart = figure.figure_title("O:TSLA220902P00273330")\
        .new_chart(row=0,col=0) \
        .x_axis(business_time=True)\
        .plot_ohlc(series_name="t4", t=t4.where(filters=["symbol = option_symbol"]), x="tdate", open="bar_open", high="bar_high", low="bar_low", close="bar_close")\
        .new_chart(row=1,col=0) \
        .plot_xy(series_name="BB_U_1_0", t=t4.where(filters=["symbol = option_symbol'"]), x="tdate", y="BB_U_1_0")\
        .new_chart(row=2,col=0) \
        .plot_xy(series_name="BB_M_1_0", t=t4.where(filters=["symbol = option_symbol"]), x="tdate", y="BB_M_1_0")\
        .new_chart(row=3,col=0) \
        .plot_xy(series_name="BB_L_1_0", t=t4.where(filters=["symbol = option_symbol"]), x="tdate", y="BB_L_1_0")\
        .new_chart(row=4,col=0) \
        .plot_xy(series_name="BB_U_2_0", t=t4.where(filters=["symbol = option_symbol"]), x="tdate", y="BB_U_2_0")\
        .new_chart(row=5,col=0) \
        .plot_xy(series_name="BB_M_2_0", t=t4.where(filters=["symbol = option_symbol"]), x="tdate", y="BB_M_2_0")\
        .new_chart(row=6,col=0) \
        .plot_xy(series_name="BB_L_2_0", t=t4.where(filters=["symbol = option_symbol"]), x="tdate", y="BB_L_2_0")\
        .show()

niloc132 added a commit to niloc132/deephaven-core that referenced this issue Oct 12, 2022
@niloc132
Copy link
Member

Updated the original query to use our current py api:

from deephaven import agg
from deephaven import read_csv
from deephaven.plot import Figure

cryptoTrades = read_csv("https://media.githubusercontent.com/media/deephaven/examples/main/CryptoCurrencyHistory/CryptoTrades_20210922.csv")

agg_list = [
    agg.last(["CloseTime = Timestamp"]),
    agg.first(["OpenTime = Timestamp"]),
    agg.max_(["High = Price"]),
    agg.min_(["Low = Price"]),
]

btcBin = cryptoTrades.where("Instrument=`BTC/USD`").update("TimestampBin = lowerBin(Timestamp, MINUTE)")
tOHLC = btcBin.agg_by(aggs=agg_list, by="TimestampBin").\
 join(table=btcBin, on="CloseTime = Timestamp", joins="Close = Price").\
 join(table=btcBin, on="OpenTime = Timestamp", joins="Open = Price")

figure = Figure()
plotOHLC = figure.plot_ohlc(series_name="BTC", t=tOHLC, x="TimestampBin", open="Open", high="High", low="Low", close="Close")\
   .chart_title(title="BTC OHLC - Aug 22 2021")\
   .x_twin()\
   .plot_xy(series_name="Open", t=tOHLC, x="TimestampBin", y="Open")\
   .show()

@hhashim1
Copy link

Updated the original query to use our current py api:

from deephaven import agg
from deephaven import read_csv
from deephaven.plot import Figure

cryptoTrades = read_csv("https://media.githubusercontent.com/media/deephaven/examples/main/CryptoCurrencyHistory/CryptoTrades_20210922.csv")

agg_list = [
    agg.last(["CloseTime = Timestamp"]),
    agg.first(["OpenTime = Timestamp"]),
    agg.max_(["High = Price"]),
    agg.min_(["Low = Price"]),
]

btcBin = cryptoTrades.where("Instrument=`BTC/USD`").update("TimestampBin = lowerBin(Timestamp, MINUTE)")
tOHLC = btcBin.agg_by(aggs=agg_list, by="TimestampBin").\
 join(table=btcBin, on="CloseTime = Timestamp", joins="Close = Price").\
 join(table=btcBin, on="OpenTime = Timestamp", joins="Open = Price")

figure = Figure()
plotOHLC = figure.plot_ohlc(series_name="BTC", t=tOHLC, x="TimestampBin", open="Open", high="High", low="Low", close="Close")\
   .chart_title(title="BTC OHLC - Aug 22 2021")\
   .x_twin()\
   .plot_xy(series_name="Open", t=tOHLC, x="TimestampBin", y="Open")\
   .show()

@niloc132 I get the below error when running your latest script.

r-Scheduler-Serial-1 | i.d.s.s.SessionState      | Internal Error 'ebcc6054-fe2d-4325-ac82-f9acd792e4c3' java.lang.RuntimeException: Error in Python interpreter:
Type: <class 'RuntimeError'>
Value: io.deephaven.plot.errors.PlotUnsupportedOperationException: Plot Information: Chart: BTC OHLC - Aug 22 2021. Attempting to create inconsistent plot types: OHLC, XY
	at io.deephaven.plot.ChartImpl.setChartType(ChartImpl.java:166)
	at io.deephaven.plot.AxesImpl.configureXYPlot(AxesImpl.java:228)
	at io.deephaven.plot.AxesImpl.plot(AxesImpl.java:1268)
	at io.deephaven.plot.AxesImpl.plot(AxesImpl.java:1309)
	at io.deephaven.plot.FigureImpl.plot(FigureImpl.java:2604)
	at io.deephaven.plot.FigureImpl.plot(FigureImpl.java:51)
	at org.jpy.PyLib.executeCode(Native Method)
	at org.jpy.PyObject.executeCode(PyObject.java:138)
	at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:73)
	at io.deephaven.integrations.python.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:185)
	at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:49)
	at io.deephaven.integrations.python.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:184)
	at io.deephaven.engine.util.AbstractScriptSession.lambda$evaluateScript$1(AbstractScriptSession.java:144)
	at io.deephaven.engine.context.ExecutionContext.lambda$apply$0(ExecutionContext.java:123)
	at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:134)
	at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:122)
	at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:144)
	at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:87)
	at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:113)
	at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:170)
	at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1342)
	at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:879)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:161)
	at java.base/java.lang.Thread.run(Thread.java:833)

Line: 1357
Namespace: plot_xy
File: /opt/deephaven/venv/lib/python3.10/site-packages/deephaven/plot/figure.py
Traceback (most recent call last):
  File "<string>", line 20, in <module>
  File "/opt/deephaven/venv/lib/python3.10/site-packages/deephaven/plot/figure.py", line 1357, in plot_xy

        at org.jpy.PyLib.executeCode(PyLib.java:-2)
        at org.jpy.PyObject.executeCode(PyObject.java:138)
        at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:73)
        at io.deephaven.integrations.python.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:185)
        at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:49)
        at io.deephaven.integrations.python.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:184)
        at io.deephaven.engine.util.AbstractScriptSession.lambda$evaluateScript$1(AbstractScriptSession.java:144)
        at io.deephaven.engine.context.ExecutionContext.lambda$apply$0(ExecutionContext.java:123)
        at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:134)
        at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:122)
        at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:144)
        at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:87)
        at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:113)
        at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:170)
        at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1342)
        at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:879)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:161)
        at java.lang.Thread.run(Thread.java:833)

@niloc132
Copy link
Member

niloc132 commented Oct 12, 2022 via email

niloc132 added a commit to niloc132/deephaven-core that referenced this issue Nov 11, 2022
niloc132 added a commit that referenced this issue Dec 1, 2022
Allows a chart to contain both XY/scatter and ohlc data, though twin()
must still be used to share axes.

Fixes #2094
mofojed pushed a commit that referenced this issue Jul 4, 2024
Release notes
https://github.com/deephaven/web-client-ui/releases/tag/v0.84.0

### ⚠ BREAKING CHANGES

* - @deephaven/jsapi-components - The contract of
`useSearchableViewportData` to be more consistent with
`useViewportData`. `usePickerWithSelectedValues` now requires
`timeZone`.
- @deephaven/jsapi-utils - `createSearchTextFilter` requires `timeZone`

### Features

* useSearchableViewportData - support non-text filters
([#2092](deephaven/web-client-ui#2092))
([7009e21](deephaven/web-client-ui@7009e21)),
closes [#2102](deephaven/web-client-ui#2102)
[#2091](deephaven/web-client-ui#2091)


### Bug Fixes

* `isElementOfType` Improved type inference
([#2099](deephaven/web-client-ui#2099))
([e13c9d7](deephaven/web-client-ui@e13c9d7)),
closes [#2094](deephaven/web-client-ui#2094)
* Console does not scroll to bottom when code run from notebook
([#2114](deephaven/web-client-ui#2114))
([e75e716](deephaven/web-client-ui@e75e716))
* make textValue default to key for Normalized Item
([#2113](deephaven/web-client-ui#2113))
([bd3e944](deephaven/web-client-ui@bd3e944))
* Update IrisGridContextMenuHandler getHeaderActions return type to be
more permissive
([#2117](deephaven/web-client-ui#2117))
([4e08b79](deephaven/web-client-ui@4e08b79))

Co-authored-by: deephaven-internal <66694643+deephaven-internal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plotting triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants