'How to interpolate more points without losing the shape of the image
I am making a polygon shape do the a simulation with matplotlib and using plt.fill to fill in the shape. What I want to do is to increase the number of points for x and y without losing the shape. But when I try to interpolate the shape is lot.
from scipy.interpolate import interp1d
import pandas as pd
import matplotlib.pyplot as plt
var = pd.read_excel("pathtotheexcel\lens1.ods", engine="odf")
x = list(var['x'])
y = list(var['y'])
#Plotting original image
plt.fill(x, y, 'k')
plt.show()
#Doing interpolation
f = interp1d(x, y, kind='nearest')
xnew = np.linspace(min(x), max(x), 1000000)
plt.plot(xnew, f(xnew))
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot(x, y)
ax1.set_title('Without Interpolate')
ax2.plot(xnew, f(xnew))
ax2.set_title('With Interpolation')
fig.show()
The attached is the plot of the differences.
As you can see on the right there are some "jiggling" with the interpolation. How can I get a smoother plot with more points? I want to increase the number of points for both x and y coordinates without losing the shape of the plot.
You can find the lens data for plotting here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

