1

I start using Plotly.NET for plotting. Everything was OK until I start plot 3D surfaces and my axis title disappear.

There is part of the code

my_func(double[] x, string[] y, double[,] z)

//...

LinearAxis xAxis = LinearAxis();
xAxis.SetValue("title", "axis title");

Layout layout = new Layout();
layout.SetValue("xaxis", xAxis);

Trace surface = new Trace("surface");
surface.SetValue("x", x);
surface.SetValue("y", y);
surface.SetValue("z", z);

GenericChart.ofTraceObject(true, surface).WithLayout(layout: layout).Show();

And axis still the default.

There is plot

I want to change AxisTitle and to know what the problem is

Please help

I try to use Plotly.NET.CSharp instead Plotly.NET

I also try this construction:

 Chart.Surface<double, double, double,string>(
        zData: new double[][] {new double[]{1,1}, new double[]{1,1}},
        X: new double[] { 1, 2 }, 
        Y: new double[] { 5, 10 })
   .WithXAxisStyle<double, double, string>(Title: Plotly.NET.Title.init("xAxis"))
   .WithYAxisStyle<double, double, string>(Title: Plotly.NET.Title.init("yAxis"))
   .Show();

It doesn't help, but other functions such as WithSize, WithTraceInfo and etc. work fine

Chart.Surface<double, double, double,string>(zData: new double[][] {new double[]{1,1}, new double[]{1,1}},
        X: new double[] { 1, 2 }, 
        Y: new double[] { 5, 10 },  ShowScale: false)
.WithSize(1500,1500).WithTraceInfo(Name: "Name", ShowLegend: true, LegendGroupTitle: Plotly.NET.Title.init("TITLE") )
    .Show();

This is plot in Plotly.NET.CSharp with custom size and etc.

TomatPast
  • 21
  • 5

1 Answers1

1

You are working with the lowest API level of Plotly.NET, where you set values directly on the objects (via SetValue). To use this layer effectively, you have to know how plotls.js (the library Plotly.NET uses) expects values. More on the different API layers can for example be read in our paper

In the case of axis objects on 3D plots, plotly.js schema differs from 2D cartesian plots by having a scene object which contains the x, y, and z axis instead of directly using the layout's xaxis and yaxis attributes (more here).

So with that knowledge, you can set axis objects on 3D plots via initializing a scene object:

var x = Enumerable.Range(0, 10).Select(i => (double)i).ToArray();
var y = Enumerable.Range(0, 10).Select(i => (double)i).ToArray();
var z = Enumerable.Range(0, 10).Select(i => (double)i).ToArray();

LinearAxis xAxis = new LinearAxis();
xAxis.SetValue("title", "x axis title");
LinearAxis yAxis = new LinearAxis();
yAxis.SetValue("title", "y axis title");
LinearAxis zAxis = new LinearAxis();
zAxis.SetValue("title", "z axis title");

Scene scene = new Scene();
scene.SetValue("xaxis", xAxis);
scene.SetValue("yaxis", yAxis);
scene.SetValue("zaxis", zAxis);

Layout layout = new Layout();
layout.SetValue("scene", scene);

Trace point = new Trace("scatter3d");
point.SetValue("x", x);
point.SetValue("y", y);
point.SetValue("z", z);

GenericChart.ofTraceObject(trace:point, useDefaults: true)
.WithLayout(layout)

plot result

Edit for Plotly.NET.CSharp

in Plotly.NET.CSharp, you must set the Id argument of the WithAxisStyle methods to Scene like this:

using Plotly.NET.CSharp;

Chart.Surface<double, double, double,string>(
    zData: new double[][] {new double[]{1,1}, new double[]{1,1}},
    X: new double[] { 1, 2 }, 
    Y: new double[] { 5, 10 })
.WithXAxisStyle<double, double, string>(Title: Plotly.NET.Title.init("xAxis"), Id: Plotly.NET.StyleParam.SubPlotId.Scene.NewScene(1))
.WithYAxisStyle<double, double, string>(Title: Plotly.NET.Title.init("yAxis"), Id: Plotly.NET.StyleParam.SubPlotId.Scene.NewScene(1))

plot result for Plotly.NET.CSharp

kMutagene
  • 177
  • 10