-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotter.py
73 lines (48 loc) · 1.65 KB
/
plotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: UTF-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from functions import rosenbrock
ax = None
def plot3d_init():
global ax
fig = plt.figure()
ax = fig.gca(projection='3d')
"""
def log_tick_formatter(val, pos=None):
return "{:.2e}".format(10**val)
ax.zaxis.set_major_formatter(mticker.FuncFormatter(log_tick_formatter))
"""
import matplotlib.ticker as mticker
def plot_func(func=rosenbrock):
s = 0.25 # Try s=1, 0.25, 0.1, or 0.05
X = np.arange(-10, 10.+s, s) #Could use linspace instead if dividing
Y = np.arange(-10, 10.+s, s) #evenly instead of stepping...
#Create the mesh grid(s) for all X/Y combos.
X, Y = np.meshgrid(X, Y)
#Rosenbrock function w/ two parameters using numpy Arrays
Z = func(X,Y)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False) #Try coolwarm vs jet
#ax.plot(X,Y,Z)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
def plot_3d_dot(xs,ys,zs, **args):
ax.scatter(xs,ys,zs, **args)
def plot(x,y, **args):
plt.plot(x,y, **args)
def plot_show(pause_time=.0, **args):
while True:
try:
plt.show(**args)
#plt.draw()
plt.pause(pause_time)
except UnicodeDecodeError:
continue
break
if __name__ == "__main__":
plot_func()
plot_show()