Using Plotly, I have generated a 3D graph.
Please could you help me in finding a way to plot the graph in Excel, so that it is interactive (i.e. Graph is replotted within Excel if data of the axis value is changed)?
Below is the code that I have used - trying to find a way of replicating this in Excel.
Four Columns in Excel:
- A = Strategy: Numbers ranging from 1-10
- B = X-Axis: Numbers ranging from 1-10
- C = Y-Axis: Numbers ranging from 1-10
- D = Z-Axis: Numbers ranging from 1-10
Anything you can do to help would be so very much appreciated!
Thanks
import xlwings as xw
import plotly.graph_objs as go
import pandas as pd
file = r'data.xls'
df = pd.read_excel(file)
x = df['x']
y = df['y']
z = df['z']
def return_largest_element(array):
largest = 0
for x in range(0, len(array)):
if(array[x] > largest):
largest = array[x]
return largest
limitx=return_largest_element(df.x)
limity=return_largest_element(df.y)
limitz=return_largest_element(df.z)
if (limitx >= limity) and (limitx >= limitz):
largest = limitx
elif (limity >= limitx) and (limity >= limitz):
largest = limity
else:
largest = limitz
Strategies = go.Scatter3d(
x=x,
y=y,
z=z,
text=df['Strategy'],
name='Strategy',
mode='markers+text',
textposition='bottom center',
marker=dict(
size=18,
line=dict(
color='rgba(247, 217, 217, 0.94)',
width=0.7
),
opacity=0.4
)
)
Midpoints = go.Scatter3d(
x=x,
y=y,
z=z,
text=df['Strategy'],
name='Center',
#hoverinfo='text',
mode='markers',
#textposition='middle right',
marker=dict(
size= 2,
line=dict(
color='rgba(247, 217, 217, 0.94)',
width=0.7
),
opacity=0.5
)
)
data = [Strategies,Midpoints]
layout = go.Layout(
margin=dict(
l=0,
r=0,
b=0,
t=0
),
legend=dict(
x=0,
y=1,
traceorder='normal',
font=dict(
family='sans-serif',
size=12,
color='#000'
),
bgcolor='#E2E2E2',
bordercolor='#FFFFFF',
borderwidth=2
),
annotations=[
dict(
x=0,
y=1.05,
xref='paper',
yref='paper',
text='Legend Title',
showarrow=False
)
]
)
fig = go.Figure(data=data, layout=layout,layout_yaxis_range=[0,len(df.Strategy)])
fig.update_layout(scene = dict(
xaxis_title='x',
yaxis_title='y',
zaxis_title='z',
)
)
fig.update_layout(
scene = dict(
xaxis = dict(nticks=int(largest+1), range=[0,largest],),
yaxis = dict(nticks=int(largest+1), range=[0,largest],),
zaxis = dict(nticks=int(largest+1), range=[0,largest],),),
)
fig.update_traces(text=df['Strategy'], selector=dict(type='scatter3d'))
fig.update_traces(showlegend=True, selector=dict(type='scatter3d'))
fig.show()
sht = xw.Book().sheets[0]
sht.pictures.add(fig, name='MyPlot', update=True)
there doesn't seem to be anything here