6
votes

I am working with plotly version 3.9.0 and python 3.7 . I am trying to render a simple surface plot in plotly using python. I have successfully rendered the plot with the intended color scheme but am having trouble with changing the axis titles of the X,Y,Z axes and also with controlling the tick frequency and tick labels for each of the axes. I have tried some of the solutions from other related questions on SO without much success. Hence, I wanted to post a snippet of my code below to seek help from the SO community about how I can go about changing the axis labels and also set the axis ticks and tick labels.

import plotly.plotly as py
import plotly.graph_objs as go

data = [
    go.Surface(
        z = p    # p is a 2D square matrix.
    )
]
data[0]['surfacecolor'] = u   #Setting surface color with another 2D square matrix `u` of the same shape as `p` 

layout = go.Layout(
         xaxis = go.layout.XAxis(
        title = go.layout.xaxis.Title(
                  text='x Axis'),
         font=dict(
         family='Courier New, monospace',
         size=18,
         color='#7f7f7f'
         )
    ),
    title = go.layout.Title(
        text='Mean Pressure Field 0.25 Granularity, Colored by Mean Particle Velocity (X-direction)'
    ),
    autosize=False,
    width=1000,
    height=1000,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    ),
)

fig = go.Figure(data=data, 
                layout=layout)

py.iplot(fig, filename='saveplot.png')

Here is the figure that I have been able to produce with the above code (with the new title for the X axis specified). Notice that the x axis label does not match the new title specified.

3D Surface Plot Plotly Python

1

1 Answers

11
votes

Replace this block:

xaxis = go.layout.XAxis(
        title = go.layout.xaxis.Title(
                  text='x Axis'),
         font=dict(
         family='Courier New, monospace',
         size=18,
         color='#7f7f7f'
         )
    )

By this:

scene = dict(
                    xaxis = dict(
                        title='X AXIS TITLE'),
                        font=dict(
                                  family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')
                    yaxis = dict(
                        title='Y AXIS TITLE'),
                    zaxis = dict(
                        title='Z AXIS TITLE'),),

See this source. Feel free to ask any more questions!