Skip to content

Instantly share code, notes, and snippets.

@jtheisen
Created April 6, 2017 17:01
Show Gist options
  • Save jtheisen/180a78be63b6a56ec7a3463c896f32aa to your computer and use it in GitHub Desktop.
Save jtheisen/180a78be63b6a56ec7a3463c896f32aa to your computer and use it in GitHub Desktop.
import plotly.offline as py
from plotly.graph_objs import *
import cmath
#from colorsys import *
import pandas as pd
import numpy
# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')
def makeSurface(cx, cy, r, s, fun):
xrange = numpy.arange(cx - r, cx + r, s)
yrange = numpy.arange(cy - r, cy + r, s)
matrix = [ [fun(x, y) for x in xrange] for y in yrange]
return Surface(x = xrange, y = yrange, z = matrix)
def makeComplexSurface(c, r, s, fun):
return makeSurface(c.real, c.imag, r, s,
lambda x, y: abs(fun(x + 1j * y))
)
#surface = makeComplexSurface(0, 2, .02, lambda x: 1 / (((x ** 2) - 1) * (x + 2 - 1j)))
def makeSurface2(c, r, n, fun):
xrange = numpy.mgrid[0:n] * 2. * r / n - r - c.real
yrange = numpy.mgrid[0:n] * 2. * r / n - r - c.imag
grid = numpy.fromfunction(lambda x, y: y * 1j + x, (n, n), dtype = int) * 2. * r / n - r - r * 1j - c
matrix = numpy.abs(fun(grid))
return Surface(x = xrange, y = yrange, z = matrix)
surface = makeSurface2(0, 2, 1000, lambda x: numpy.log(x))
fig = Figure(data = [ surface ],
layout = Layout(scene = Scene(zaxis = ZAxis(range = [-1, 5])))
)
py.plot(fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment