You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plotly.NET(C#)绘制3D曲面时轴标题不显示问题求助

Plotly.NET 3D曲面图轴标题不显示的解决方案

3D曲面图的轴配置逻辑和2D图表不同——2D图表的轴直接挂在顶层layout的xaxis/yaxis属性下,但3D图表的所有轴(X/Y/Z)都嵌套在layout.scene对象中。你之前的两种写法都误用了2D轴的配置方式,所以轴标题无法生效。

方案1:底层对象配置(适配你最初的写法)

修改Layout的配置,将轴设置放在scene对象内,而非直接设置顶层xaxis:

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

// 配置各轴标题
LinearAxis xAxis = LinearAxis();
xAxis.SetValue("title", "X轴标题");
LinearAxis yAxis = LinearAxis();
yAxis.SetValue("title", "Y轴标题");
LinearAxis zAxis = LinearAxis();
zAxis.SetValue("title", "Z轴标题");

// 创建Scene对象并挂载轴
Scene scene = new Scene();
scene.SetValue("xaxis", xAxis);
scene.SetValue("yaxis", yAxis);
scene.SetValue("zaxis", zAxis);

// 将Scene加入Layout
Layout layout = new Layout();
layout.SetValue("scene", scene);

// 创建曲面Trace并展示
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();

方案2:Plotly.NET.CSharp流畅API(推荐)

使用WithScene或WithSceneAxisStyle方法来配置3D场景的轴,替代针对2D的WithXAxisStyle:

方式A:链式配置Scene

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 })
   .WithScene(scene => scene
       .WithXAxis(x => x.SetTitle("X轴标题"))
       .WithYAxis(y => y.SetTitle("Y轴标题"))
       .WithZAxis(z => z.SetTitle("Z轴标题")))
   .Show();

方式B:单独设置各场景轴

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 })
   .WithSceneAxisStyle(AxisId.X, title: Plotly.NET.Title.init("X轴标题"))
   .WithSceneAxisStyle(AxisId.Y, title: Plotly.NET.Title.init("Y轴标题"))
   .WithSceneAxisStyle(AxisId.Z, title: Plotly.NET.Title.init("Z轴标题"))
   .Show();

内容的提问来源于stack exchange,提问作者TomatPast

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 10:37:03