Contour Line Interpolation

Hi there,

I was curious, by what interpolation method are contour lines calculated in Plotly?
I can find no documentation nor reproduce the results; for instance of the following code:
p <- plot_ly(srtest, x=X, y=Y, z=O,type =“contour”)

One other issue. I have a csv with X Y and Z values. Now when initially run the command above, generally the code runs and I’m shown a contour plot of the data. Now if I delete a single row from the X Y and Z data in the csv and save, import the csv into R, and run the exact same command as above, plotly returns a graph labeled from 0 to 6 on the x axis and 0 to -4 on the y axis with absolutely no points in it. No error message is observed.

If I add the data point and resave the plot works again, and I can even add a new row with additional xyz data and it’ll include it in the interpretation. Any ideas as to what would cause this behavior?

In regards to the second question about the plot working and then not working, it seems sometimes when the CSV is imported into R there will be a couple extra empty rows added after the data. Simply deleting them appears to solve the problem, as whatever the interpolation algorithm is, it doesn’t appear to enjoy having NA’s. Now, if anyone knows how it goes interpolating the contours …?

This looks like a bug to me.

Would you mind sharing a reproducible code snippet?

Sometimes it happens, sometimes it doesn’t while using read.csv, with that said, you can avoid the problem entirely by running
data.omitted <-na.omit(data). That has cleared up that issue.

But do you happen to know what is the algorithm the contour inter/extrapolation is based on?
So far with fitting trend surfaces, idw, kriging and akima I haven’t been able to replicate it.

We’re using the marching squares algorithm.

You can check our complete implementation here.


Thank you Etienne, and thanks for Plotly!