python-3.xpandasdata-visualizationplotlydata-analysis

Hide Legend and Scale information on surface plot using pandas, plotly


I am at my wits end but so far did not find any documentation to solve my specific issue. I am using jupyter notebook.

I have two data frames, df1 & df2.

# libraries
import pandas as pd
import numpy as np

import matplotlib.pyplot as plt
import cufflinks as cf
cf.go_offline()
import plotly.graph_objs as go

# df1 & df2
np.random.seed(0)
dates = pd.date_range('20130101',periods=6)

df1 = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
df2 = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))

I have two surface plots:

layout = go.Layout(
    title='Random Numbers',
    autosize=False,
    width=500,
    height=500,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    )
)

df1.iplot(kind="surface", layout=layout)
df2.iplot(kind="surface", layout=layout)

I have three problems:

  1. I need to plot them side by side as in (row = 1 & column = 2).
  2. The scale legend is either removed or is shared.
  3. The x and y in the axes are removed. I do not need to change them, just get rid of these.

Sample Surface from df1

Any help will be appreciated.


Solution

  • I'm sorry if this doesn't answer your question directly but I would suggest using plotly without cufflings.

    import plotly
    
    # Define scene which changes the default attributes of the chart
    scene = dict(
        xaxis=dict(title=''),
        yaxis=dict(title=''),
        zaxis=dict(title='')
    )
    
    # Create 2 empty subplots
    fig = plotly.tools.make_subplots(rows=1, cols=2,
                                     specs=[[{'is_3d': True}, {'is_3d': True}]])
    # Add df1
    fig.append_trace(dict(type='surface', x=df1.index, y=df1.columns, z=df1.as_matrix(), 
                          colorscale='Viridis', scene='scene1', showscale=False), 1, 1)
    
    # Add df2
    fig.append_trace(dict(type='surface', x=df2.index, y=df2.columns, z=df2.as_matrix(), 
                          colorscale='RdBu', scene='scene2', showscale=False), 1, 2)
    
    # Set layout and change defaults with scene
    fig['layout'].update(title='Random Numbers', height=400, width=800)
    fig['layout']['scene1'].update(scene)
    fig['layout']['scene2'].update(scene)
    
    # Use plotly offline to display the graph
    plotly.offline.plot(fig)
    

    Output:

    enter image description here

    EDIT:

    To answer your third question, you can use .update(scene) to change the axis attributes. Details are in the code above.