✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Adjusting Margin/Padding on Axes for 3dPlot

Hi everyone,

Right now I have an issue that a 3d scatter plot that I’m creating has tick marks that overlap with the axis labels.

Here is a picture demonstrating what I mean:

Ideally I’d like to do at least one of the following:

  • Change the font size of either the axis labels or tick marks
  • Change the padding or margin on either the tick labels or tick marks themselves so I can change the distance between them so they don’t overlap

On the instructions page for 3d charts I do not see this listed anywhere.

Here is the sample code that I have:

import plotly.express as px
import dash
import dash_core_components as dcc  
import dash_html_components as html
import pandas as pd
import numpy as np

df = pd.read_csv('https://raw.githubusercontent.com/JonathanBechtel/ml_chart/master/data.csv')
rands = np.random.normal(0, 0.1, size=(df.shape[0], 3))
num_cols = ['Data Source', 'Target Variable', 'Prediction Type']
df[num_cols] = df[num_cols]+rands

fig = px.scatter_3d(df, x='Data Source', y='Target Variable', z='Prediction Type',
          color='Family', width=1000, height=700, title='Machine Learning Exploration', 
          hover_data={'Family': True, 'Technique': True, 'Data Source': False, 'Target Variable': 
False, 'Prediction Type': False, 'Description': False},
          range_x=[-.15, 1.15], range_y=[-.15, 1.15], range_z=[-1.15, 1.15])

fig.update_layout(scene={'xaxis': {'ticktext': ['Unstructured', 'Structured'], 
                               'tickvals': [0, 1],
                               'showbackground': False},
                     'yaxis': {'ticktext': ['Unsupervised', 'Supervised'],
                               'tickvals': [0, 1]}, 
                     'zaxis': {'ticktext': ['Classification', 'Regression', 'Grouping'],
                               'tickvals': [0, 1, -1]},
                     'xaxis_showspikes': False,
                     'yaxis_showspikes': False,
                     'zaxis_showspikes': False})

  app = dash.Dash()
  app.layout = html.Div([
  dcc.Graph(figure=fig)
])

app.run_server(debug=True, use_reloader=False)