Here is my Python code, which gives me a plot:
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import cufflinks as cf
import pandas as pd
import numpy as np
%matplotlib inline
df3 = pd.DataFrame({'x':[1,2,3,4,5],'y':[10,20,30,20,10],'z':[5,4,3,2,1]})
df3.iplot(kind='surface',colorscale='rdylbu')
Pyhton output is:
Then I tried to recreate the same data frame and plot the plot, however, got an error
x<-c(1,2,3,4,5)
y=c(10,20,30,20,10)
z=c(5,4,3,2,1)
df3 = data.frame(x,y,z)
plot_ly(x = df3$x, y = df3$y, z = df3$z) %>% add_surface()
Error: `z` must be a numeric matrix
#also tried
plot_ly(data = data.frame(df)) %>% add_surface()
Error: Must supply `z` attribute
How can I get the plot in R? Also assume I got z as categorical z=c("a","b","c","d","e"), can I plot with this values?
question from:
https://stackoverflow.com/questions/65950835/why-plotly-function-needs-different-data-formats-in-python-and-r-to-plot-3d-surf