Skip to content

Surface

Overview

The surface trace type is used to create 3D surface plots, which visualize 3D data on a continuous surface. Surface plots are ideal for visualizing the relationship between three variables, often showing the interaction of two independent variables on a dependent variable. These plots are useful for understanding the shape of the data in three dimensions.

You can customize the colorscale, lighting, and contours to represent the surface data effectively.

Common Uses

  • 3D Data Visualization: Visualizing three variables with two independent variables and one dependent variable.
  • Topographical Maps: Representing elevations or contours of landscapes.
  • Heatmaps in 3D: Showing intensity variations in a 3D format.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple surface plot showing a continuous 3D surface:

You can copy this code below to create this chart in your project:

models:
  - name: surface-data
    args:
      - echo
      - |
        x,y,z
        1,1,1
        1,2,2
        1,3,3
        2,1,4
        2,2,5
        2,3,6
        3,1,7
        3,2,8
        3,3,9
traces:
  - name: Simple Surface Plot
    model: ${ref(surface-data)}
    props:
      type: surface
      x: ?{x}
      y: ?{y}
      z: ?{z}
charts:
  - name: Simple Surface Chart
    traces:
      - ${ref(Simple Surface Plot)}
    layout:
      title:
        text: Simple Surface Plot<br><sub>3D Surface Visualization</sub>

This example demonstrates a surface plot with a custom colorscale applied to the surface:

Here's the code:

models:
  - name: surface-data-colorscale
    args:
      - echo
      - |
        x,y,z
        1,1,1
        1,2,2
        1,3,3
        2,1,4
        2,2,5
        2,3,6
        3,1,7
        3,2,8
        3,3,9
traces:
  - name: Surface Plot with Custom Colorscale
    model: ${ref(surface-data-colorscale)}
    props:
      type: surface
      x: ?{x}
      y: ?{y}
      z: ?{z}
      colorscale: "Viridis"
charts:
  - name: Surface Chart with Custom Colorscale
    traces:
      - ${ref(Surface Plot with Custom Colorscale)}
    layout:
      title:
        text: Surface Plot with Custom Colorscale<br><sub>Custom Colorscale for 3D Surface</sub>

Here's a surface plot where contour lines are added to the surface, highlighting the shape of the surface more clearly:

Here's the code:

models:
  - name: surface-data-contours
    args:
      - echo
      - |
        x,y,z
        1,1,1
        1,2,2
        1,3,3
        2,1,4
        2,2,5
        2,3,6
        3,1,7
        3,2,8
        3,3,9
traces:
  - name: Surface Plot with Contours
    model: ${ref(surface-data-contours)}
    props:
      type: surface
      x: ?{x}
      y: ?{y}
      z: ?{z}
      contours:
        z:
          show: true
          usecolormap: true
          highlightcolor: "#ff0000"
charts:
  - name: Surface Chart with Contours
    traces:
      - ${ref(Surface Plot with Contours)}
    layout:
      title:
        text: Surface Plot with Contours<br><sub>3D Surface with Contour Lines</sub>

A schema to validate plotly trace properties

Attributes

These attributes apply to traces where trace.props.type is set to surface. You would configure these attributes on the trace with the trace.props object.

autocolorscale: boolean
cauto: boolean
cmax: number
cmid: number
cmin: number
coloraxis: string
colorbar:
  bgcolor: any
  bordercolor: any
  borderwidth: number
  exponentformat: any
  len: number
  lenmode: any
  minexponent: number
  nticks: integer
  orientation: any
  outlinecolor: any
  outlinewidth: number
  separatethousands: boolean
  showexponent: any
  showticklabels: boolean
  showtickprefix: any
  showticksuffix: any
  thickness: number
  thicknessmode: any
  tickangle: number
  tickcolor: any
  tickfont:
    color: any
    family: 'string' #(1)!
    lineposition: any
    shadow: 'string' #(2)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  tickformat: 'string' #(3)!
  tickformatstops: array
  ticklabeloverflow: any
  ticklabelposition: any
  ticklabelstep: integer
  ticklen: number
  tickmode: any
  tickprefix: 'string' #(4)!
  ticks: any
  ticksuffix: 'string' #(5)!
  ticktext: array
  ticktextsrc: 'string' #(6)!
  tickvals: array
  tickvalssrc: 'string' #(7)!
  tickwidth: number
  title:
    font:
      color: any
      family: 'string' #(8)!
      lineposition: any
      shadow: 'string' #(9)!
      size: number
      style: any
      textcase: any
      variant: any
      weight: integer
    side: any
    text: 'string' #(10)!
  x: number
  xanchor: any
  xpad: number
  xref: any
  y: number
  yanchor: any
  ypad: number
  yref: any
colorscale: any
connectgaps: boolean
contours:
  x:
    color: any
    end: number
    highlight: boolean
    highlightcolor: any
    highlightwidth: number
    project:
      x: boolean
      y: boolean
      z: boolean
    show: boolean
    size: number
    start: number
    usecolormap: boolean
    width: number
  y:
    color: any
    end: number
    highlight: boolean
    highlightcolor: any
    highlightwidth: number
    project:
      x: boolean
      y: boolean
      z: boolean
    show: boolean
    size: number
    start: number
    usecolormap: boolean
    width: number
  z:
    color: any
    end: number
    highlight: boolean
    highlightcolor: any
    highlightwidth: number
    project:
      x: boolean
      y: boolean
      z: boolean
    show: boolean
    size: number
    start: number
    usecolormap: boolean
    width: number
customdata: array
customdatasrc: 'string' #(11)!
hidesurface: boolean
hoverinfo: array
hoverinfosrc: 'string' #(12)!
hoverlabel:
  align: array
  alignsrc: 'string' #(13)!
  bgcolor: array
  bgcolorsrc: 'string' #(14)!
  bordercolor: array
  bordercolorsrc: 'string' #(15)!
  font:
    color: array
    colorsrc: 'string' #(16)!
    family: 'string | array' #(17)!
    familysrc: 'string' #(18)!
    lineposition: array
    linepositionsrc: 'string' #(19)!
    shadow: 'string | array' #(20)!
    shadowsrc: 'string' #(21)!
    size: array
    sizesrc: 'string' #(22)!
    style: array
    stylesrc: 'string' #(23)!
    textcase: array
    textcasesrc: 'string' #(24)!
    variant: array
    variantsrc: 'string' #(25)!
    weight: array
    weightsrc: 'string' #(26)!
  namelength: array
  namelengthsrc: 'string' #(27)!
hovertemplate: 'string | array' #(28)!
hovertemplatesrc: 'string' #(29)!
hovertext: 'string | array' #(30)!
hovertextsrc: 'string' #(31)!
ids: array
idssrc: 'string' #(32)!
legend: string
legendgroup: 'string' #(33)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(34)!
    lineposition: any
    shadow: 'string' #(35)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  text: 'string' #(36)!
legendrank: number
legendwidth: number
lighting:
  ambient: number
  diffuse: number
  fresnel: number
  roughness: number
  specular: number
lightposition:
  x: number
  y: number
  z: number
metasrc: 'string' #(37)!
name: 'string' #(38)!
opacity: number
reversescale: boolean
scene: string
showlegend: boolean
showscale: boolean
stream:
  maxpoints: number
  token: 'string' #(39)!
surfacecolor: array
surfacecolorsrc: 'string' #(40)!
text: 'string | array' #(41)!
textsrc: 'string' #(42)!
type: surface
uid: 'string' #(43)!
visible: any
x: array
xcalendar: any
xhoverformat: 'string' #(44)!
xsrc: 'string' #(45)!
y: array
ycalendar: any
yhoverformat: 'string' #(46)!
ysrc: 'string' #(47)!
z: array
zcalendar: any
zhoverformat: 'string' #(48)!
zsrc: 'string' #(49)!
  1. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  2. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  3. Sets the tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46
  4. Sets a tick label prefix.
  5. Sets a tick label suffix.
  6. Sets the source reference on Chart Studio Cloud for ticktext.
  7. Sets the source reference on Chart Studio Cloud for tickvals.
  8. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  9. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  10. Sets the title of the color bar.
  11. Sets the source reference on Chart Studio Cloud for customdata.
  12. Sets the source reference on Chart Studio Cloud for hoverinfo.
  13. Sets the source reference on Chart Studio Cloud for align.
  14. Sets the source reference on Chart Studio Cloud for bgcolor.
  15. Sets the source reference on Chart Studio Cloud for bordercolor.
  16. Sets the source reference on Chart Studio Cloud for color.
  17. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  18. Sets the source reference on Chart Studio Cloud for family.
  19. Sets the source reference on Chart Studio Cloud for lineposition.
  20. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  21. Sets the source reference on Chart Studio Cloud for shadow.
  22. Sets the source reference on Chart Studio Cloud for size.
  23. Sets the source reference on Chart Studio Cloud for style.
  24. Sets the source reference on Chart Studio Cloud for textcase.
  25. Sets the source reference on Chart Studio Cloud for variant.
  26. Sets the source reference on Chart Studio Cloud for weight.
  27. Sets the source reference on Chart Studio Cloud for namelength.
  28. Template string used for rendering the information that appear on hover box. Note that this will override hoverinfo. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%xother}, {%_xother}, {%xother_}. When showing info for several points, xother will be added to those with different x positions from the first point. An underscore before or after (x|y)other will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in hovertemplate are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are arrayOk: true) are available. Anything contained in tag <extra> is displayed in the secondary box, for example "{fullData.name}". To hide the secondary box completely, use an empty tag <extra></extra>.
  29. Sets the source reference on Chart Studio Cloud for hovertemplate.
  30. Same as text.
  31. Sets the source reference on Chart Studio Cloud for hovertext.
  32. Sets the source reference on Chart Studio Cloud for ids.
  33. Sets the legend group for this trace. Traces and shapes part of the same legend group hide/show at the same time when toggling legend items.
  34. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  35. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  36. Sets the title of the legend group.
  37. Sets the source reference on Chart Studio Cloud for meta.
  38. Sets the trace name. The trace name appears as the legend item and on hover.
  39. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  40. Sets the source reference on Chart Studio Cloud for surfacecolor.
  41. Sets the text elements associated with each z value. If trace hoverinfo contains a text flag and hovertext is not set, these elements will be seen in the hover labels.
  42. Sets the source reference on Chart Studio Cloud for text.
  43. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  44. Sets the hover text formatting rulefor x using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using xaxis.hoverformat.
  45. Sets the source reference on Chart Studio Cloud for x.
  46. Sets the hover text formatting rulefor y using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using yaxis.hoverformat.
  47. Sets the source reference on Chart Studio Cloud for y.
  48. Sets the hover text formatting rulefor z using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using zaxis.hoverformat.
  49. Sets the source reference on Chart Studio Cloud for z.