Documentation
Documentation copied to clipboard
Add C# Plotting Examples in Research
Expected Behavior
To have examples of C# plotting libraries, e.g. Plotly.NET.
Actual Behavior
QuantConnect images support this library, but we haven't been able to make it work in the coding environment yet.
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
Is it possible that the Plotly.NET assemblies are not getting loaded by the notebook environment?
I got it to work. There are two issues 1) The Plotly assemblies are not automatically loaded by the research notebook environment, 2) The .Show() method does not work with QC Notebooks (not sure why)
As a workaround for now, do the following.
- Manually load the Plotly.NET assembly
#r "/home/jovyan/Plotly.NET.dll"
// Plotly.NET.Interactive.dll is not needed for the workaround
// #r "/home/jovyan/Plotly.NET.Interactive.dll"
- Instead of calling the .Show method on a GenericChart object, generate HTML directly and use the notebook HTML() function to display HTML inline.
For instance (showing what works and what doesn't)
using Plotly.NET;
using Plotly.NET.LayoutObjects;
// Plotly.NET.Interactive is not needed for the workaround
// using Plotly.NET.Interactive;
double[] x = new double[] { 1, 2 };
double[] y = new double[] { 5, 10 };
LinearAxis xAxis = new LinearAxis();
xAxis.SetValue("title", "xAxis");
xAxis.SetValue("showgrid", false);
xAxis.SetValue("showline", true);
LinearAxis yAxis = new LinearAxis();
yAxis.SetValue("title", "yAxis");
yAxis.SetValue("showgrid", false);
yAxis.SetValue("showline", true);
Layout layout = new Layout();
layout.SetValue("xaxis", xAxis);
layout.SetValue("yaxis", yAxis);
layout.SetValue("showlegend", true);
Trace trace = new Trace("scatter");
trace.SetValue("x", x);
trace.SetValue("y", y);
trace.SetValue("mode", "markers");
trace.SetValue("name", "Hello from C#");
var c = GenericChart
.ofTraceObject(true, trace)
.WithLayout(layout);
// DOES NOT WORK
// c.Show()
// DOES WORK
HTML(GenericChart.toChartHTML(c))