add interpolations graphics for thesis
This commit is contained in:
parent
db1bb89fbd
commit
c541cf8f3d
2 changed files with 133 additions and 0 deletions
83
visualisation.py
Normal file
83
visualisation.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
# from scipy.spatial import voronoi_plot_2d, Delaunay
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
from scipy.spatial.qhull import Delaunay
|
||||
from matplotlib.axes import Axes
|
||||
|
||||
np.random.seed(10)
|
||||
|
||||
points = np.random.rand(100, 2)
|
||||
|
||||
testpoint = (0.7, 0.7)
|
||||
fig1 = plt.figure()
|
||||
ax = fig1.add_subplot() # type:Axes
|
||||
fig2 = plt.figure()
|
||||
ax2 = fig2.add_subplot() # type:Axes
|
||||
fig3=plt.figure()
|
||||
ax3d = fig3.add_subplot(projection='3d') # type:Axes3D
|
||||
|
||||
# vor = Voronoi(grid)
|
||||
#
|
||||
#
|
||||
# fig = voronoi_plot_2d(vor)
|
||||
tri = Delaunay(points)
|
||||
print(type(tri))
|
||||
ax.scatter(points[:, 0], points[:, 1])
|
||||
ax2.scatter(points[:, 0], points[:, 1])
|
||||
#
|
||||
center_tri = tri.find_simplex(np.array([testpoint]))[0]
|
||||
print(center_tri)
|
||||
print(tri.simplices[center_tri])
|
||||
|
||||
ax.scatter(*testpoint, color="green", zorder=2)
|
||||
ax2.scatter(*testpoint, color="green", zorder=2)
|
||||
close_points = []
|
||||
for dot in tri.simplices[center_tri]:
|
||||
point = tri.points[dot]
|
||||
z = (point[0] - 0.5) ** 2 + (point[1] - 0.5) ** 2
|
||||
close_points.append([point[0], point[1], z])
|
||||
print(point)
|
||||
print("test")
|
||||
ax2.scatter(point[0], point[1], color="red", zorder=2)
|
||||
ax3d.scatter(point[0], point[1], z, color="red", zorder=2)
|
||||
ax2.triplot(points[:, 0], points[:, 1], tri.simplices.copy())
|
||||
# plt.show()
|
||||
# plt.close()
|
||||
close_points = np.asarray(close_points)
|
||||
z = (points[:, 0] - 0.5) ** 2 + (points[:, 1] - 0.5) ** 2
|
||||
|
||||
ax3d.scatter(points[:, 0], points[:, 1], z)
|
||||
|
||||
p1, p2, p3 = close_points
|
||||
|
||||
v1 = p3 - p1
|
||||
v2 = p2 - p1
|
||||
|
||||
print(v1, v2)
|
||||
|
||||
# the cross product is a vector normal to the plane
|
||||
cp = np.cross(v1, v2)
|
||||
print(cp)
|
||||
a, b, c = cp
|
||||
|
||||
# This evaluates a * x3 + b * y3 + c * z3 which equals d
|
||||
d = np.dot(cp, p3)
|
||||
|
||||
x = np.linspace(0.5, .9, 5)
|
||||
y = np.linspace(0.5, .9, 5)
|
||||
X, Y = np.meshgrid(x, y)
|
||||
|
||||
Z = (d - a * X - b * Y) / c
|
||||
|
||||
z_center = (d - a * testpoint[0] - b * testpoint[1]) / c
|
||||
|
||||
ax3d.scatter(*testpoint, z_center, color="green")
|
||||
|
||||
ax3d.plot_surface(X, Y, Z, color="lightgreen", alpha=0.4)
|
||||
|
||||
|
||||
fig1.savefig("../arbeit/images/vis2d1.pdf")
|
||||
fig2.savefig("../arbeit/images/vis2d2.pdf")
|
||||
fig3.savefig("../arbeit/images/vis2d3.pdf")
|
||||
plt.show()
|
50
visualisation1d.py
Normal file
50
visualisation1d.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
np.random.seed(15)
|
||||
|
||||
fig, (ax1, ax2) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 20]})
|
||||
# Hide the right and top spines
|
||||
ax1.spines['right'].set_visible(False)
|
||||
ax1.spines['top'].set_visible(False)
|
||||
ax2.spines['right'].set_visible(False)
|
||||
ax2.spines['top'].set_visible(False)
|
||||
ax1.spines['left'].set_visible(False)
|
||||
ax1.yaxis.set_visible(False)
|
||||
ax1.set_ylim(0, 1)
|
||||
ax1.xaxis.set_ticks_position('bottom')
|
||||
|
||||
points = np.sort(np.random.rand(20))
|
||||
print(points)
|
||||
testpoint = 0.4
|
||||
|
||||
ax1.scatter(points, np.zeros_like(points) + 0.5)
|
||||
ax1.scatter(testpoint, 0.5, color="green")
|
||||
|
||||
for i, val in enumerate(points):
|
||||
if val > testpoint:
|
||||
next_i = i
|
||||
prev_i = i - 1
|
||||
break
|
||||
|
||||
Y = np.sin(points * 6)
|
||||
|
||||
ax2.scatter(points, Y)
|
||||
ax2.scatter(points[prev_i], Y[prev_i], color="red")
|
||||
ax1.scatter(points[prev_i], 0.5, color="red")
|
||||
ax2.scatter(points[next_i], Y[next_i], color="red")
|
||||
ax1.scatter(points[next_i], 0.5, color="red")
|
||||
|
||||
a, b = np.polyfit([points[prev_i], points[next_i]], [Y[prev_i], Y[next_i]], 1)
|
||||
print(a, b)
|
||||
|
||||
linex = np.linspace(0.3, 0.6, 2)
|
||||
liney = b + a * linex
|
||||
|
||||
testy = b + a * testpoint
|
||||
|
||||
ax2.plot(linex, liney, color="lightgreen", zorder=-2)
|
||||
ax2.scatter(testpoint, testy, color="green")
|
||||
|
||||
plt.savefig("../arbeit/images/vis1d.pdf")
|
||||
plt.show()
|
Reference in a new issue