#!/usr/bin/env python
# coding: utf-8
# #### New to Plotly?
# Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).
# You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).
# We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
# ### Range of axes
# In[1]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
N = 70
trace1 = go.Mesh3d(x=(70*np.random.randn(N)),
y=(55*np.random.randn(N)),
z=(40*np.random.randn(N)),
opacity=0.5,
color='rgba(244,22,100,0.6)'
)
layout = go.Layout(
scene = dict(
xaxis = dict(
nticks=4, range = [-100,100],),
yaxis = dict(
nticks=4, range = [-50,100],),
zaxis = dict(
nticks=4, range = [-100,100],),),
width=700,
margin=dict(
r=20, l=10,
b=10, t=10)
)
fig = go.Figure(data=[trace1], layout=layout)
py.iplot(fig, filename='3d-axis-range')
# ### Fixed Ratio Axes
# In[2]:
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.tools as tls
import numpy as np
N = 50
fig = tls.make_subplots(
rows=2, cols=2,
specs=[
[{'is_3d': True}, {'is_3d': True}],
[{'is_3d': True}, {'is_3d': True}]
],
print_grid=False
)
for i in [1,2]:
for j in [1,2]:
fig.append_trace(
go.Mesh3d(
x=(60*np.random.randn(N)),
y=(25*np.random.randn(N)),
z=(40*np.random.randn(N)),
opacity=0.5,
),
row=i, col=j)
fig['layout'].update(go.Layout(
width=700,
margin=dict(
r=10, l=10,
b=10, t=10)
))
# fix the ratio in the top left subplot to be a cube
fig['layout'][].update(go.Layout(
go.layout.Scene(aspectmode='cube')),
# manually force the z-axis to appear twice as big as the other two
fig['layout']['scene2'].update(go.layout.Scene(
aspectmode='manual',
aspectratio=go.layout.scene.Aspectratio(
x=1, y=1, z=2
)
))
# draw axes in proportion to the proportion of their ranges
fig['layout']['scene3'].update(go.layout.Scene(aspectmode='data'))
# automatically produce something that is well proportioned using 'data' as the default
fig['layout']['scene4'].update(go.layout.Scene(aspectmode='auto'))
py.iplot(fig, filename='3d-axis-fixed-ratio-axes')
# ### Set Axes Title
# In[3]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
N = 50
trace1 = go.Mesh3d(x=(60*np.random.randn(N)),
y=(25*np.random.randn(N)),
z=(40*np.random.randn(N)),
opacity=0.5,
color='yellow'
)
trace2 = go.Mesh3d(x=(70*np.random.randn(N)),
y=(55*np.random.randn(N)),
z=(30*np.random.randn(N)),
opacity=0.5,
color='pink'
)
layout = go.Layout(
scene = dict(
xaxis = dict(
title='X AXIS TITLE'),
yaxis = dict(
title='Y AXIS TITLE'),
zaxis = dict(
title='Z AXIS TITLE'),),
width=700,
margin=dict(
r=20, b=10,
l=10, t=10)
)
fig = go.Figure(data=[trace1,trace2], layout=layout)
py.iplot(fig, filename='3d-axis-titles')
# ### Ticks Formatting
# In[4]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
N = 50
trace1 = go.Mesh3d(x=(60*np.random.randn(N)),
y=(25*np.random.randn(N)),
z=(40*np.random.randn(N)),
opacity=0.5,
color='rgba(100,22,200,0.5)'
)
layout = go.Layout(
scene = dict(
xaxis = dict(
ticktext= ['TICKS','MESH','PLOTLY','PYTHON'],
tickvals= [0,50,75,-50]),
yaxis = dict(
nticks=5, tickfont=dict(
color='green',
size=12,
family='Old Standard TT, serif',),
ticksuffix='#'),
zaxis = dict(
nticks=4, ticks='outside',
tick0=0, tickwidth=4),),
width=700,
margin=dict(
r=10, l=10,
b=10, t=10)
)
fig = go.Figure(data=[trace1], layout=layout)
py.iplot(fig, filename='3d-axis-tick-formatting')
# ### Background and Grid Color
# In[5]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
N = 50
trace1 = go.Mesh3d(x=(30*np.random.randn(N)),
y=(25*np.random.randn(N)),
z=(30*np.random.randn(N)),
opacity=0.5,)
layout = go.Layout(
scene = dict(
xaxis = dict(
backgroundcolor="rgb(200, 200, 230)",
gridcolor="rgb(255, 255, 255)",
showbackground=True,
zerolinecolor="rgb(255, 255, 255)",),
yaxis = dict(
backgroundcolor="rgb(230, 200,230)",
gridcolor="rgb(255, 255, 255)",
showbackground=True,
zerolinecolor="rgb(255, 255, 255)"),
zaxis = dict(
backgroundcolor="rgb(230, 230,200)",
gridcolor="rgb(255, 255, 255)",
showbackground=True,
zerolinecolor="rgb(255, 255, 255)",),),
width=700,
margin=dict(
r=10, l=10,
b=10, t=10)
)
fig = go.Figure(data=[trace1], layout=layout)
py.iplot(fig, filename='3d-axis-background-and-grid-color')
# In[7]:
from IPython.display import display, HTML
display(HTML(''))
display(HTML(''))
get_ipython().system(' pip install git+https://github.com/plotly/publisher.git --upgrade')
import publisher
publisher.publish(
'3d-axes.ipynb', 'python/3d-axes/', 'Axes Formatting in 3d Plots | plotly',
'How to format axes of 3d plots in Python with Plotly.',
title = 'Format 3d Axes | plotly',
name = '3D Axes',
has_thumbnail='true', thumbnail='thumbnail/3d-axes.png',
language='python', page_type='example_index',
display_as='3d_charts', order=0.101,
ipynb= '~notebook_demo/96')
# In[ ]: